PyIPD is a Python module for playing around with the Iterated Prisoner's Dilemma. It's based on the computer tournament run by Robert Axelrod and described in his book The Evolution of Co-operation. Most of the decision rules included here are re-coded (with varying degrees of success) from this source.
The Prisoner's Dilemma is a two-player, two-option game. The options available to each player are co-operate or defect. Played with the standard payoffs, possible results are:
Cold, calculating logic says the best move is to always defect: whatever the opponent does, you always get more points. The dilemma is that when your opponent deduces the same, you're both going to get only 1 point each. But if only you had both co-operated, you'd both be 2 points richer!
The main point of Robert Axelrod's book is that even though in a one-shot Prisoner's Dilemma defection is the only logical outcome, when the players play the game repeatedly those prepared to co-operate will do better, because there is the possibility of building up mutual trust. Axelrod ran a series of contests which pitted different playing strategies against each other, with some pretty interesting results.
This module allows you to run your own versions of these contests. Here's some example output from the round-robin tournament:
263.1 NPF Forgiving_Tit_For_Tat 255.1 .PF Downing 254.3 NPF Tit_For_Two_Tats 254.2 NP. Tit_For_Tat 253.5 NPF Revised_State_Transition 245.2 NPF Soft_Majority 240.3 NP. Two_Tits_For_Tat 240.3 .PF Tester 238.1 NPF Revised_Downing 233.4 NP. Spiteful 232.6 .PF Periodic_CCD 228.9 N.F All_C 227.2 .PF Periodic_CD 225.6 NPF Pavlov 223.6 .PF Random 220.9 .P. Tranquilizer 209.7 .P. Suspicious_Tit_For_Tat 205.0 .P. Joss 200.0 .PF Periodic_DDC 194.8 .PF Hard_Majority 178.0 .P. All_D