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
b2b40999
Commit
b2b40999
authored
Nov 05, 2020
by
Julian Rudolf
Browse files
fixed an issue with inital state after reset
parent
ba1f6a9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Agent/agent.py
View file @
b2b40999
...
...
@@ -90,7 +90,6 @@ class QLearning:
print
(
dirs
)
# returns all possible actions
# TODO: maby possible != not kill
def
possible_directions
(
self
):
poss_actions
=
[]
# if not state.kill_l:
...
...
@@ -140,6 +139,7 @@ def learning(al, ga, ep, games):
print
(
"Starting learning process!"
)
for
i
in
range
(
max_games
):
playerwin
=
play_game_learning
(
qagent
,
q_0
,
poss_dirs_0
)
q_0
,
poss_dirs_0
=
reset
()
print
(
"Game "
,
i
+
1
,
"/"
,
max_games
,
" finished!"
)
if
playerwin
==
1
:
score
[
0
]
+=
1
...
...
Agent/snake_logic.py
View file @
b2b40999
...
...
@@ -523,7 +523,6 @@ def step(action):
reward
=
0
print
(
"Apples eaten: "
,
snake1
.
getscore
())
reset
()
agent_apples
=
[]
for
a
,
id
in
apples
:
for
apple
in
a
:
...
...
@@ -577,8 +576,8 @@ def step(action):
playerwin
=
2
if
check_if_crossing
(
snake1
.
pos
[
0
]
/
block_size
,
snake1
.
pos
[
1
]
/
block_size
):
# print("Action needed!")
reward
-=
1
if
not
init
:
reward
-=
1
agent_apples
=
[]
for
a
,
id
in
apples
:
for
apple
in
a
:
...
...
@@ -662,6 +661,8 @@ def reset():
snake2
.
set_enemy_norm_snake
(
snake1
)
gameExit
=
False
playerwin
=
0
state
,
_
,
_
,
poss_dirs
=
step
(
"init"
)
return
state
,
poss_dirs
# exit game
...
...
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