-
Notifications
You must be signed in to change notification settings - Fork 0
/
myZombie.py
200 lines (159 loc) · 7.5 KB
/
myZombie.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import zombiedice
import random
class MyZombie:
def __init__(self, name):
# All zombies must have a name:
self.name = name
def turn(self, gameState):
# gameState is a dict with info about the current state of the game.
# You can choose to ignore it in your code.
diceRollResults = zombiedice.roll() # first roll
# roll() returns a dictionary with keys 'brains', 'shotgun', and
# 'footsteps' with how many rolls of each type there were.
# The 'rolls' key is a list of (color, icon) tuples with the
# exact roll result information.
# Example of a roll() return value:
# {'brains': 1, 'footsteps': 1, 'shotgun': 1,
# 'rolls': [('yellow', 'brains'), ('red', 'footsteps'),
# ('green', 'shotgun')]}
# REPLACE THIS ZOMBIE CODE WITH YOUR OWN:
brains = 0
while diceRollResults is not None:
brains += diceRollResults['brains']
if brains < 2:
diceRollResults = zombiedice.roll() # roll again
else:
break
class TwoBrainZombie:
def __init__(self, name):
# All zombies must have a name:
self.name = name
def turn(self, gameState):
# gameState is a dict with info about the current state of the game.
# You can choose to ignore it in your code.
diceRollResults = zombiedice.roll() # first roll
# roll() returns a dictionary with keys 'brains', 'shotgun', and
# 'footsteps' with how many rolls of each type there were.
# The 'rolls' key is a list of (color, icon) tuples with the
# exact roll result information.
# Example of a roll() return value:
# {'brains': 1, 'footsteps': 1, 'shotgun': 1,
# 'rolls': [('yellow', 'brains'), ('red', 'footsteps'),
# ('green', 'shotgun')]}
# REPLACE THIS ZOMBIE CODE WITH YOUR OWN:
brains = diceRollResults['brains']
shouldRole = brains < 2
while diceRollResults is not None and shouldRole:
diceRollResults = zombiedice.roll() # roll again
if diceRollResults is not None:
brains += diceRollResults['brains']
shouldRole = brains < 2
class RandomZombie:
def __init__(self, name):
# All zombies must have a name:
self.name = name
def turn(self, gameState):
# gameState is a dict with info about the current state of the game.
# You can choose to ignore it in your code.
diceRollResults = zombiedice.roll() # first roll
# roll() returns a dictionary with keys 'brains', 'shotgun', and
# 'footsteps' with how many rolls of each type there were.
# The 'rolls' key is a list of (color, icon) tuples with the
# exact roll result information.
# Example of a roll() return value:
#
# REPLACE THIS ZOMBIE CODE WITH YOUR OWN:
shouldRole = random.randint(0, 1) == 1
while diceRollResults is not None and shouldRole:
shouldRole = random.randint(0, 1) == 1
diceRollResults = zombiedice.roll() # roll again
class TwoShotgunZombie:
def __init__(self, name):
# All zombies must have a name:
self.name = name
def turn(self, gameState):
# gameState is a dict with info about the current state of the game.
# You can choose to ignore it in your code.
diceRollResults = zombiedice.roll() # first roll
# roll() returns a dictionary with keys 'brains', 'shotgun', and
# 'footsteps' with how many rolls of each type there were.
# The 'rolls' key is a list of (color, icon) tuples with the
# exact roll result information.
# Example of a roll() return value:
#
# REPLACE THIS ZOMBIE CODE WITH YOUR OWN:
shotguns = diceRollResults.get('shotgun', 0)
shouldRole = shotguns < 2
while diceRollResults is not None and shouldRole:
diceRollResults = zombiedice.roll() # roll again
if diceRollResults is not None:
shotguns += diceRollResults['shotgun']
shouldRole = shotguns < 2
class OneToFourZombie:
def __init__(self, name):
# All zombies must have a name:
self.name = name
def turn(self, gameState):
# gameState is a dict with info about the current state of the game.
# You can choose to ignore it in your code.
diceRollResults = zombiedice.roll() # first roll
# roll() returns a dictionary with keys 'brains', 'shotgun', and
# 'footsteps' with how many rolls of each type there were.
# The 'rolls' key is a list of (color, icon) tuples with the
# exact roll result information.
# Example of a roll() return value:
#
# REPLACE THIS ZOMBIE CODE WITH YOUR OWN:
numberOfRolls = random.randint(1, 4)
timesRolled = 1
shotguns = diceRollResults.get('shotgun', 0)
shouldRole = shotguns < 2 and timesRolled < numberOfRolls
while diceRollResults is not None and shouldRole:
diceRollResults = zombiedice.roll() # roll again
timesRolled += 1
if diceRollResults is not None:
shotguns += diceRollResults['shotgun']
shouldRole = shotguns < 2 and timesRolled < numberOfRolls
class ShotgunZombie:
def __init__(self, name):
# All zombies must have a name:
self.name = name
def turn(self, gameState):
# gameState is a dict with info about the current state of the game.
# You can choose to ignore it in your code.
diceRollResults = zombiedice.roll() # first roll
# roll() returns a dictionary with keys 'brains', 'shotgun', and
# 'footsteps' with how many rolls of each type there were.
# The 'rolls' key is a list of (color, icon) tuples with the
# exact roll result information.
# Example of a roll() return value:
#
# REPLACE THIS ZOMBIE CODE WITH YOUR OWN:
numberOfRolls = random.randint(1, 4)
shotguns = diceRollResults['shotgun']
brains = diceRollResults['brains']
shouldRole = shotguns <= brains
while diceRollResults is not None and shouldRole:
diceRollResults = zombiedice.roll() # roll again
if diceRollResults is not None:
shotguns += diceRollResults['shotgun']
brains += diceRollResults['shotgun']
shouldRole = shotguns <= brains
zombies = (
zombiedice.examples.RandomCoinFlipZombie(name='Random'),
zombiedice.examples.RollsUntilInTheLeadZombie(name='Until Leading'),
zombiedice.examples.MinNumShotgunsThenStopsZombie(
name='Until 2 Shotguns', minShotguns=2),
zombiedice.examples.MinNumShotgunsThenStopsZombie(
name='Until 1 Shotgun', minShotguns=1),
MyZombie(name='My Zombie Bot'),
RandomZombie(name='My Random'),
TwoBrainZombie(name='My TwoBrain stopper'),
TwoShotgunZombie(name='My TwoShotgun stopper'),
OneToFourZombie(name='My OneToFour zombie'),
ShotgunZombie(name='My Shotgun zombie'),
# Add any other zombie players here.
)
# Uncomment one of the following lines to run in CLI or Web GUI mode:
# zombiedice.runTournament(zombies=zombies, numGames=1000)
zombiedice.runWebGui(zombies=zombies, numGames=1000)