Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
scos
scos.projects
2PSnake
Commits
73e1fd10
Commit
73e1fd10
authored
Nov 16, 2020
by
Julian Rudolf
Browse files
agent now on all maps
parent
14eafdee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Agent/state.py
View file @
73e1fd10
...
...
@@ -176,9 +176,11 @@ def search(dir, head, apples, steps, max_steps=50, kill=0, crossing=False):
# calculates nearest apple from all directions
# determines if enemy snake travels towards agent snake on neighboring edges
# returns a Feature object
def
calc_state_space
(
snake_agent
,
snake_enemy
,
apples
):
def
calc_state_space
(
snake_agent
,
snake_enemy
,
apples
,
map_
):
global
map
global
head_e
global
dir_e
map
=
map_
head
=
snake_agent
.
pos
[
1
]
/
block_size
,
snake_agent
.
pos
[
0
]
/
block_size
dir
=
snake_agent
.
direction
head_e
=
snake_enemy
.
pos
[
1
]
/
block_size
,
snake_enemy
.
pos
[
0
]
/
block_size
...
...
Game/main.py
View file @
73e1fd10
...
...
@@ -1198,7 +1198,7 @@ def game_loop():
for
apple
in
a
:
if
img
==
purple_apple
:
agent_apples
.
append
((
int
(
apple
.
pos
[
0
]
/
block_size
),
int
(
apple
.
pos
[
1
]
/
block_size
)))
state
=
calc_state_space
(
snake2
,
snake1
,
agent_apples
)
state
=
calc_state_space
(
snake2
,
snake1
,
agent_apples
,
map
)
action
=
snake2
.
choose_best_action
(
qtable
,
state
)
snake2
.
key_event
(
action
)
action_taken
=
True
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment