Running a Game

In order to run a game, you need to import the domination module, and either create a Scenario, or create a Game object directly.

Creating a Game object directly

The simplest way you can use the game object, is to just instantiate it and call its run() method. This will run a game with all its default settings:

from domination import core
core.Game(rendered=True).run() # Set rendered=False if you don't have pygame.

However, creating a game object directly is useful mainly if you want to do some fiddling with its internals, so we recommend skipping right to Creating Agents or Using Scenarios.

If we like, we can mess around a bit with the game object and its properties:

from domination import core

# Make it a short game
settings = core.Settings(max_steps=20)

# Initialize a game
game = core.Game('domination/','domination/',
    record=True, rendered=False, settings=settings)

# Will run the entire game.

# And now let's see the replay!
replay = game.replay
playback = core.Game(replay=replay)


The Game class has the following specification.

class domination.core.Game(red=<open file '/home/docs/checkouts/', mode 'r'>, blue=<open file '/home/docs/checkouts/', mode 'r'>, red_init={}, blue_init={}, settings=Settings(), field=None, record=False, replay=None, rendered=True, verbose=True, hard_errors=False, step_callback=None)[source]

The main game class. Contains game data and methods for simulation.

Constructor for Game class

  • red – Descriptor of the red agent. Can be either a path, an open file, a string with the class definition, or an instance of Team
  • blue – Descriptor of the blue agent
  • red_init – A dictionary of keyword arguments passed to the red agent constructor.
  • blue_init – Like red_init.
  • settings – Instance of the settings class.
  • field – An instance of Field to play this game on, or a generator.
  • record – Store all actions in a game replay.
  • replay – Pass a game replay to play it.
  • rendered – Enable/disable the renderer.
  • verbose – Print game log to output.
  • hard_errors – Enable to make agent errors interrupt the game.
  • step_callback – Function that is called on every step. Useful for debugging.
log = None

The game log as an instance of class:~domination.core.GameLog

replay = None

The replay object, can be accessed after game has run

stats = None

Instance of GameStats.

red = None

Instance of Team.

blue = None

Instance of Team.


Start and loop the game.

class domination.core.GameStats[source]
score_red = None

The number of points scored by red

score_blue = None

The number of points scored by blue

score = None

The final score as a float (red/total)

steps = None

Number of steps the game lasted

ammo_red = None

Number of ammo packs that red picked up

ammo_blue = None

Idem for blue

deaths_red = None

Number red agents that got shot

deaths_blue = None

Number blue agents that got shot

think_time_red = None

Total time in seconds that red took to compute actions

think_time_blue = None

Idem for blue


Running replays is easy, first you need to unpack them:

>>> import pickle
>>> from domination import core
>>> rp = pickle.load(open('replay20120215-1341_t2v1_vs_t6v1.pickle','rb'))
>>> print rp
<domination.core.ReplayData object at 0x10fca5fd0>

Then you call the play method:

class domination.core.ReplayData(game)[source]

Contains the replaydata for a game.


Convenience method for setting up a game to play this replay.


class domination.core.Settings(max_steps=600, max_score=400, max_turn=1.0471975511965976, max_speed=40, max_range=60, max_see=100, field_known=True, ammo_rate=20, ammo_amount=3, agent_type='tank', spawn_time=10, tilesize=16, think_time=0.01, capture_mode=2, end_condition=1)[source]

Constructor for Settings class

  • max_steps – How long the game will last at most
  • max_score – If either team scores this much, the game is finished
  • max_speed – Number of game units each tank can drive in its turn
  • max_turn – The maximum angle that a tank can rotate in a turn
  • max_range – The shooting range of tanks in game units
  • max_see – How far tanks can see (vision is a square with sides that are 2x this value)
  • field_known – Whether the agents have knowledge of the field at game start
  • ammo_rate – How long it takes for ammo to reappear
  • ammo_amount – How many bullets there are in each ammo pack
  • agent_type – Type of the agents (‘tank’ or ‘vacubot’)
  • spawn_time – Time that it takes for tanks to respawn
  • think_time – How long the tanks have to do their computations (in seconds)
  • capture_mode – One of the CAPTURE_MODE constants.
  • end_condition – One of the ENDGAME flags. Use bitwise OR for multiple.
  • tilesize – How big a single tile is (game units), change at risk of massive bugginess

The Settings.capture_mode can be one of:

domination.core.CAPTURE_MODE_NEUTRAL = 0

Controlpoints are neutral when occupied by both teams

domination.core.CAPTURE_MODE_FIRST = 1

Controlpoints stay in control of first team that captures them

domination.core.CAPTURE_MODE_MAJORITY = 2

Controlpoints are owned by the team with the most occupiers

The Settings.end_condition can be one of:

domination.core.ENDGAME_NONE = 0

End game when time expires

domination.core.ENDGAME_SCORE = 1

End game when either team has 0 score

domination.core.ENDGAME_CRUMBS = 2

End game when all crumbs are picked up