Warning
This page is located in archive.

Player

Detailed specification for tournament players follow.

File to turn in

All the code needed for the player to function has to be in file name player.py. This file (and only this file) has to be uploaded through the upload system.

MyPlayer Class and its methods

First we have to realize that the players do not communicate directly, but through intermediary, which will call the players and archive their results. Players are to be implemented in the MyPlayer class which has to have these methods:

Method Input parameters Output parameters Explanation
__init__ payoff_matrix, number_of_iterations none Creates the player instance. The player will always receive the payoff matrix, but it may or may not receive number of iterations. Method must be able to work either way. The player is expected to store those values and can use them to decide upon his strategy. You can find details in the files for download. (At the bottom)
move none False or True Generates your move. False means cooperate, True means defect.
record_opponents_move opponent_move none Player receives opponent's move. It is either False (Cooperate) or True (Defect).

Description string

Player class, has to have a description in form of doc-string. Maximal length is 80 character. It should explain how the player plays. i.e.

class MyPlayer:
    '''The player plays what she wants to, mostly C'''
    def __init__ # ... and so on, a standard code continues

Payoff Matrix

Two dimensional field of tuples. First row and column, index 0, correspond to COOPERATE, second row and second column to DEFECT.

Thus, the profit for player A, if he plays COOPERATE and player B plays DEFECT, is

payoff_matrix[0][1][0]
Last index corresponds to player, A=0, B=1. Symbolically it can also be written as:
payoff_matrix[COOPERATE][DEFECT][0]
In our games, we will only use symmetrical payoff matrix, so the player does not have to known whether he is player A or B, as both have the same chances.

Player cannot

  • Write anything to the harddrive
  • Attempt to communicate with the other player or process or anything else
  • Be curious (browse the files on the harddrive)
  • Contain the header #!/usr/bin/python. The player.py will only be imported, not run.

It is supposed to just play.

Tournament(s)

At the end, all the players will play in a round robin tournament. The objective is to maximize your total profit. There are going to be two tournaments, basic one, for which the payoff matrix will be known, so you can specially set up your player. In the advanced tournament, the payoff matrix will be given to the player at the start of the game, thus it has to decide its strategy according to the payoff matrix. Player can change its strategy, if it chooses to.

  • The player is not going to play against itself
  • Each pair will play each other only once.

Payoff Matrix for first tournament

Matrix for the first tournament

C D
C 4, 4 1, 6
D 6, 1 2, 2

or in Python:

payoff_matrix = [ [(4,4),(1,6)] , [(6,1),(2,2)] ]
For your testing you can, and you should, also use different matrices.

Files

If you already have implemented player, you can download and look through tournament code. This ZIP archive contains two files game.py, which implements the game and test_game.py, which can take two players and let them play against each other. Read both codes and try to run them with your player. (test_game.py places two copies of your player against each other.) You can of course experiment and change both files.

courses/ae4b99rph/labs/prisoners_dilemma/specifications.txt · Last modified: 2013/10/04 13:02 (external edit)