Programming AI Bots for Zombie Dice

  • A name member which is set in the constructor function. The name uniquely identifies the bot in a tournament (this way you can have multiple bots from the same class compete against each other.)
  • A turn() method that has a gameState tuple passed to it.
  • The turn() method calls a global roll() function (zombiedice.roll() if your bot is in another file that imports zombiedice.py) as many times as it likes. The turn is over when the turn() method returns. (Calls to roll() after getting three shotgun blasts have no effect, and roll() simply returns an empty list.)
  • Optionally you can have a newGame() and/or endGame() methods that are called so that the bot can know when a game has started and ended (in case the bot should change its strategy if it is winning or losing a multi-game tournament.)

# A "skeleton" zombie class. Get it? Skeleton? Heh heh heh... eh... nevermind. class MyZombie(object): def __init__(self, name): self.name = name def newGame(self): pass # do nothing def endGame(self, gameState): pass # do nothing def turn(gameState): results = roll()

The gameState parameter is a dictionary with the following keys:

  • Key 'order' has a value of a list of player order like ['player1name', 'player2name', ...].
  • Key 'scores' has a value of a dictionary with scores like {'player1name': player1score, 'player2name': player2score, ...}.
  • Key 'round' has a value of an integer telling which round it is in the current game. (The first round is 1.)

The return value of roll() is a list of three tuples that have the color and icon of the rolls. For example:

[('green', 'shotgun'), ('red', 'footsteps'), ('yellow', 'brains')]

There are uppercase constant variables that you can use instead of string values, just to avoid typos:

[(GREEN, SHOTGUN), (RED, FOOTSTEPS), (YELLOW, BRAINS)]

For example, here’s the code for a Zombie Dice bot that keeps rolling until they have at least 3 brains:

class ThreeBrainsThenStops(object): def __init__(self, name): self.name = name def newGame(self): pass # do nothing def endGame(self, gameState): pass # do nothing def turn(self, gameState): brains = 0 while brains < 3: results = roll() if results = []: return for i in results: if i[1] == BRAINS: brains += 1

Loading Bots into the Tournament Program

Once you have the code for your bot, you can run it in a tournament by adding an instance of the bot to a list which is passed to runTournament(). For example, in zombiedice.py (the text-based tournament program):

bots = [ZombieBot_MonteCarlo('MonteCarlo', 40, 100), ZombieBot_MinNumShotgunsThenStops('Min2ShotgunsBot', 2), ZombieBot_RandomCoinFlip('RandomBot'), ] runTournament(bots, 1000)

Each object made from a bot class needs to be given a unique name in the constructor. Some classes may have other parameters for the constructor. In zombiedice_web.py, this code is here:

BOTS = [zombiedice.ZombieBot_MonteCarlo('MonteCarloBot', 40, 100), zombiedice.ZombieBot_MonteCarlo('FastMonteCarloBot', 40, 20), # executes faster because it runs fewer experimental rolls zombiedice.ZombieBot_MinNumShotgunsThenStops('Min2ShotgunsBot', 2), zombiedice.ZombieBot_MinNumShotgunsThenStops('Min1ShotgunBot', 1), #zombiedice.ZombieBot_HumanPlayer('Human'), # uncomment if you want to play (learn the rules to Zombie Dice first though) zombiedice.ZombieBot_RollsUntilInTheLead('RollsUntilInTheLeadBot'), zombiedice.ZombieBot_RandomCoinFlip('RandomBot'), ]

The code further down in zombiedice_web.py will handle launching the web server.

The Included Bots

The zombiedice.py program has some basic bots:

Page 2 of 3 |

Share