Iterated Prisoner's Dilemma
Java Simulation Classes

Java packages fr.lifl.prison, fr.lifl.prison.util, fr.lifl.prison.strategies,
Copyright © 1997-1998 by LIFL (SMAC team)

Thoses java classes are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Contact the authors for more details.

Please contact us for any bug, any difficulty or any improvement idea.
Please take last version on
Please send us an e-mail if you use this software. With your address We will be able to tell you if there has been changes in the new version or to give new contributions

Introduction to the Classical Iterated Prisoner's Dilemma

A formal model for cooperation

Let two artificial rational agents have the choice between two moves:

They play one against the other, in a synchronous manner, so that they do not know what the other will play. They get a score according to the situation of the move:

The classical choice of value for payoff is (row player payoff are given first):

Cooperate R = 3
R = 3
S = 0
T = 5
Defect T = 5
S = 0
P = 1
P = 1

To have a dilemma, temptation must pay more than cooperation, which must pay more than punishment, which must be better than to be the sucker. This is formalised by:

T > R > P > S

Since the one-shot version of the Prisoner's Dilemma is not very interesting (the most rational choice is to defect), the game is repeated an unknown number of times.
The game is said iterated.
The final score of a payer is the sum of all its moves score.
Since none player knows when the game will be ended, it is possible to study each agent's strategy, to look, for instance, how each player tries to put cooperation in the game.

In order to favour cooperation, i.e. common interest at the expens of selfish interest, this inequation is respected:

2 R > T + S

With this restriction, strategies have no advantage in alternatively cooperate and defect. To study the behavior of strategies, two kinds of computation can be done.

The basic strategies available in java-prison

Here is a description of some of the basic strategies available throw the BasicStrategies class of the fr.lifl.prison.strategies package:
Always cooperates. [c]*
Always defects. [d]*
The tit_for_tat strategy was introduced by Anatole Rapoport. It begins to cooperate, and then play what its opponent played in the last move.
It cooperates until the opponent has defected, after that move it always defects.
Plays opponent's majority move, if equal then cooperates. First move is considered to be equality.
Plays periodically : [d,d,c]*
Plays periodically : [c,c,d]*
Defects, then plays opponent's move.
Plays periodically [c,d].
The win-stay/lose-shift strategy was introduced by Martin Nowak and Karl Sigmund. It cooperates if and only if both players opted for the same choice in the previous move.
Cooperates except if opponent has defected two consecutive times.
Cooperates except if opponent has defected at least one time in the two previous move.
Plays [c,c], then if opponent plays two consecutive time the same move plays its move.
Plays opponent's majority move, if equal then defects. First move is considered to be equality.
Cooperates with probability 1/2.

The java prison libray


To use this package you just have to :
  1. Unpack the archive ;
  2. Add the prison.jar file to your CLASSPATH environment variable, see your Java Virtal Machine (probably the Sun Java Development Kit's one) documentation. For instance on UNIX under c-shell, suppose you have moved the prison.jar file into the /home/foo directory, then you will just have to say :
    setenv CLASSPATH ${CLASSPATH}:/home/foo/prison.jar

Description and use

Once you have installed the java prison library you get 3 new java packages available:
In this package are defined the main classes used to make the simulations of Iterated Prisoner's Dilemma games.
In this package are defined some classes, extending a class of the previous package called Player, in order to define some generic kind of players (strategies), as well as a class implementing an array of some basic strategies, which were described in the first section of this document.
In this package are defined some useful general utility classes which may help in making the results of Iterated Prisoner's Dilemma simulations, among other things, more human readable. It includes graphic representation of data sets, as well as matrix manipulations and quicksort algorithm. A special class called Util is used to make some links between classes of this package and classes of the fr.lifl.prison one.

The full API documentation of those packages and their classes is available in the doc directory.

Three applets demonstrating the use of java-prison, and their java sources are available in the applets directory. They are demonstrating the simulation of:

  1. A match between two strategies in the applets/match directory;
  2. A tournament between some user choosen strategies, in the applets/tournament directory;
  3. An ecological evolution involving user defined population of user choosen strategies, in the applets/evolution directory.

In order to demonstrate the localization capabilities of the java-prison library on each one of those three previous applets, french prepared html file calling the previous three applets are also available:

  1. applets/match/
  2. applets/tournament/
  3. applets/evolution/

Authors and contacts

The PRISON project is a project from the SMAC team of the LIFL at the University of Science and Technology of Lille, FRANCE.

The main interest of the SMAC team is the study of Multi Agents Systems and Cooperation. The PRISON project is the cooperation side study of the project, but uses some Multi Agents technics too. The main goal of the project being the use of computer science tools in order to collect informations on the way cooperation between autonomous agents could arise and be maintaned.

Some of the keywords of the project are : (Iterated) Prisoner's Dilemma, Cooperation, Artificial Life, Evolution, Game Theory, Multi-Agents Systems

You can contact us for any bug reports, improvement ideas, informations request, comments, if you need help in using the java-prison classes, or if you are interested by our work on the Multi Agent Systems and Cooperation. Here are the way to contact us:


The PRISON project is sponsored by :

Copyright © 1998 by LIFL, <>
Last modified: 1998/11/20 - 3:20