Iterated prisoner’s dilemma in MATALB

To assist with my upcoming project on game theory, I’ve put together some MATLAB functions to run iterated prisoner’s dilemma tournaments. In particular, this demonstrates the effects of the Southampton strategy I described a while ago on E2. MATLAB’s vector operations turned out to be particularly well suited to this, especially for handling unknown competition length or numbers of participants. The files are reasonably well documented, but I thought I’d offer some additional guidance.

Drop the files below into the same directory and run the tournament script to generate some sample output. Each program plays every other for the specified number of rounds, including itself, then a total score is obtained for each. The matrix returned gives the scores of individual pairings in the natural way; the vector is the scores. You can adjust the identities of the players by altering the vector Q defined in tournament; any number of players and any choice of strategies should work (including, of course, repeated instances of any given strategy).

play handles any given play of the game, that is, one round between two strategies, with their respective histories available. I’ve implemented always cooperate, always defect, tit-for-tat, grim, and the southampton master/slaves. Any unrecognised strategy code is treated as a random 50/50 choice, and the addition of further strategies should be fairly smooth- add another if condition that tests for your chosen number, then add that number into the player vector Q to see it in action.

I don’t know the precise details of the Southampton programs, but mine work along the same lines. A sequence of 8 moves codes for each; during the first 8 rounds, each program continues to play its signal moves unless the opponent has signalled incorrectly. From round 9 onwards, the programs will have identified their opponent as southampton slave, master or non-southampton. In the case of the latter, both strategies switch to permanent defection to reduce the opponent score. In a master-slave pairing, the master defects and the slave cooperates to maximise return to the master at the cost of the slave. Master-master or slave-slave pairings play out as mutual cooperation to bolster their scores.

The payoff matrix I use is consistent with my report, but not exactly standard. This of course can also be changed.


One Comment

Leave a Reply

Your email address will not be published.