summaryrefslogtreecommitdiff
path: root/qlearning.py
diff options
context:
space:
mode:
Diffstat (limited to 'qlearning.py')
-rwxr-xr-xqlearning.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/qlearning.py b/qlearning.py
index 6e6d54c..ee0b0a9 100755
--- a/qlearning.py
+++ b/qlearning.py
@@ -128,14 +128,16 @@ class QTable:
# Perform learning
+width,height=10,10
perf=0
last_state=None
last_action=None
-game=Snake(length=1,fps=300,startat=(random.randint(0,29),random.randint(0,29)))
+game=Snake(length=1,fps=500,startat=(random.randint(0,width-1),random.randint(0,height-1)),grid_width=width,grid_height=height)
qtable=QTable("qtable.txt")
while True:
result=0
stuck=0
+ stuck_tolerance=1
state=qtable.get_state(game)
while result >= 0:
action=qtable.get_action(state)
@@ -143,7 +145,7 @@ while True:
new_state=qtable.get_state(game)
# Agent is stuck
- if stuck>=(game.grid_width*game.grid_height)/2:
+ if stuck>=(game.grid_width*game.grid_height)/stuck_tolerance:
game.new_game()
break
@@ -153,7 +155,7 @@ while True:
reward=-10
stuck=0
elif result==1:
- reward=1
+ reward=50
stuck=0
# Apply learning