PyTitForTat Annotated source code
This is a simple example of a Python agent that plays Tit For Tat. First it cooperates, then it does whatever the other player did on the previous round. from java.lang import Runnable

You write your agent as a Python class that has a run() function (mimicking Java's Runnable). The engine will instantiate the class with no arguments and set an actor attribute on the object before calling run().

Here we put the actor and game in local scope just to make code more legible.

class TitForTat(Runnable): def run(self): actor = game = actor.getGame()
Here is the strategy. After the initial cooperation, the agent runs a loop which executes until the game is done. cooperate() and act() each wait for the round to be played, then return an object that contains each player's action and score for that round. result = actor.cooperate() while (game.isRunning()): result = actor.act(result.otherPlayerAction)
A longer Python example can be seen at genetic_prisoner.