PrisonersDilemma(proportionCoop: Float = 0.5f, benefit: Float, cost: Float = 1.0f, noGames: Int = 100)

run iterative game of prisoners dilemma

An iterative game of Prisoners’ dilemma is played on the network. In each round, vertices simultaneously play a round of Prisoners’ dilemma with their neighbours, getting a payoff according to whether each player chose to cooperate (C) or defect(D). After the game is played, a vertex adopts its strategy by choosing the highest scoring strategy in its direct neighbourhood. This carries on until either a pre-defined number of games is played or if none of the vertices change their strategy.


proportionCoop: Float=0.5f

Proportion of vertices that start out as cooperators (uniformly sampled). Alternatively, vertices starting with a status “cooperator” set to 0 begin as cooperators.

benefit: Float

Benefit parameter for prisoners’ dilemma game. See [1]

cost: Float

Cost parameter for prisoners’ dilemma game. See [1]


Maximum number of games to be played.


optional seed for testing purposes.


cooperator: Int

The latest status: cooperator (0), or defector (1), of the vertex at that iteration.

cooperationHistory: mutable.Queue[Int]

The full history of a vertex’ cooperation status for the games played.


vertex name

cooperation history

name: String

cooperationHistory: Queue[Int]


[1] Nowak, M. A., & May, R. M. (1992). Evolutionary games and spatial chaos. Nature, 359(6398), 826-829.

See also