diff --git a/qlearning.py b/qlearning.py index 5cb3d8a..a1770b6 100755 --- a/qlearning.py +++ b/qlearning.py @@ -38,7 +38,6 @@ def isWall(h,game): return(True) return(False) - def event_handler(game,event): h=game.snake[0] left=(h[0]-1,h[1]) @@ -62,6 +61,14 @@ def event_handler(game,event): obstacle_down=(down in game.snake or isWall(down, game)) obstacle_left=(left in game.snake or isWall(left, game)) + reward=0 + if event==1: + reward=1 + elif event==-1: + reward=-10 + + state=2048*snake_go_up + if game.snake[0][0]==10: game.direction=6 diff --git a/snake.py b/snake.py index 0597808..b2c8226 100755 --- a/snake.py +++ b/snake.py @@ -168,14 +168,3 @@ class Snake: pygame.display.flip() clock.tick(self.fps) return(self.score) - - -game=Snake() - -def event_handler(game): - if game.snake[0][0]==10: - game.direction=6 - -for i in range(0,10): - score=game.run() - print("Game ended with "+str(score)) \ No newline at end of file