Python simulator for the Iterated Prisoner's Dilemma, inspired by classic IPD tournaments.
This project collects a large set of strategies and runs them against each other in tournament-style matchups.
- 30+ strategy functions in
IPD_tournament/IPDStrategies.py - match simulation logic in
IPD_tournament/IPD_Simulations.py - a small entry script in
IPD_tournament/IPDtournament_main.py
IPD_tournament/IPDtournament_main.pyCurrent entry point. By default it runs:
ClassicTourney(Player_list, 200, 4)-
IPD_tournament/IPD_Simulations.pyCore tournament logic:Fight(player1, player2, playto)runs a head-to-head matchRoundRobin(playerlist, playto)computes average performance across the full poolClassicTourney(playerlist, playto, permutations)runs a bracket-style tournament
-
IPD_tournament/IPDStrategies.pyStrategy definitions and registration lists.
Moves are represented as:
1= cooperate0= defect
Payoffs: Standard
(1,1) -> (3,3)(1,0) -> (0,5)(0,1) -> (5,0)(0,0) -> (2,2)
Each strategy is a Python function that receives:
strategy(player, score, modifiers=[None])Where:
playeris player1or2scoreis the prior match history as a list of(p1_move, p2_move)tuples- the return value is usually a single move or a short list of upcoming moves
Strategies are registered in:
Player_dictPlayer_list
So adding a new strategy usually means:
- Define the function in
IPDStrategies.py - Add it to
Player_dict - Run the main script again