diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-11-02 10:29:11 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-11-02 10:29:11 +0100 |
| commit | 65280331d3b2b3d32375df783ab89f30706e17da (patch) | |
| tree | 3abafebf4632e6c71e97ff78b7405055cdfd1e4f /qlearning.py | |
| parent | 37308a0d4c475261d424da1ef7a65cdb0f10459a (diff) | |
Minor changes
Diffstat (limited to 'qlearning.py')
| -rwxr-xr-x | qlearning.py | 8 |
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 |
