Programming AI Bots for Zombie Dice

When the simulation has finished, you can reload the page to start a new tournament.

To edit which bots are being run in the simulation, modify the BOTS list at the top of

The AI Bots

Each zombie AI bot will be a class that has:

  • 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 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): = 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 dictionaries that have the color and icon of the rolls. For example:

[{'color': 'green', 'icon': 'shotgun'}, {'color': 'red', 'icon': 'footsteps'}, {'color': 'yellow', 'icon': 'brains')]

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


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): = 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[ICON] == BRAINS: brains += 1

Loading Bots into the Tournament Program

To configure a tournament, create a new Python script (called in this example, but any name is fine) and run like this:


The config file is formatted with games, ui, and bots variables:

  • games - integer, the number of games to simulate
  • ui - string, either "web" for web interface or "cli" for command line interface
  • bots - a list of lists. Each inner list represents a bot, and has values:
  • filename - string, the python file where the bot code is
  • class name - string, the name of the class
  • bot name - string, the name of the bot instance
  • args - arguments passed to the bot's constructor

Additionally, the config file can have these variables:

    verbose - boolean, if True, output game info to stdout exceptions_lose_game - boolean, if True, an exception in the bot code causes the bot to forfeit the current game. If False, an exception crashes the tournament program. max_turn_time - if None, there is no time limit for a bot's turn. Otherwise, the number of seconds the bot has per turn before forfeiting the current game.

Example file:

games = 100

ui = 'web'

bots = [

['', 'RandomCoinFlipZombie', 'Random Bot'],

['', 'MonteCarloZombie', 'Monte Carlo Bot', 40, 20],

['', 'MinNumShotgunsThenStopsZombie', 'Min Shotguns Bot', 2],


The Included Bots

The program has some basic bots:

Page 2 of 3 | Previous page | Next page