Minor changes
This commit is contained in:
parent
4f113282d7
commit
d2f75ae502
2 changed files with 8 additions and 12 deletions
|
@ -38,7 +38,6 @@ def isWall(h,game):
|
||||||
return(True)
|
return(True)
|
||||||
return(False)
|
return(False)
|
||||||
|
|
||||||
|
|
||||||
def event_handler(game,event):
|
def event_handler(game,event):
|
||||||
h=game.snake[0]
|
h=game.snake[0]
|
||||||
left=(h[0]-1,h[1])
|
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_down=(down in game.snake or isWall(down, game))
|
||||||
obstacle_left=(left in game.snake or isWall(left, 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:
|
if game.snake[0][0]==10:
|
||||||
game.direction=6
|
game.direction=6
|
||||||
|
|
||||||
|
|
11
snake.py
11
snake.py
|
@ -168,14 +168,3 @@ class Snake:
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(self.fps)
|
clock.tick(self.fps)
|
||||||
return(self.score)
|
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))
|
|
Loading…
Add table
Reference in a new issue