-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainRandomAI.py
More file actions
44 lines (33 loc) · 892 Bytes
/
mainRandomAI.py
File metadata and controls
44 lines (33 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gameloop
import random
import direction
import debug
class RandomPlayer:
def __init__(self, timeStep):
self.decision = None
self.paths = []
def think(self, board):
self.decision = None
self.paths = []
# if a snack is close gobble it
for possibility in direction.ALL:
result = board.potentialEndturnResult(possibility)
if result == board.SNACK:
self.decision = possibility
return
# check if there is no issue
elif result == board.DEATH:
pass
# added to possible paths
else: self.paths.append(possibility)
# random choice in remaining options
if self.paths : self.decision = random.choice(self.paths)
def handleKey(self, event):
pass
def getDecision(self):
return self.decision
def getPlayer(timeStep):
return RandomPlayer(timeStep)
gameloop.getPlayer = getPlayer
application = gameloop.Game()
application.run()