Here, you will find a detailed description of the required player's functionalities.
All the player's code needs to be placed in the player.py
file. You will upload this (and only this) file to BRUTE. The player can import the standard python modules, e.g., random, math.
It is important to note that the opposing players do not communicate directly. Their communication is arranged via a moderator/broker which asks the players for their response and archives the results of the match. Implement your player (file player.py
) in a form of a class called MyPlayer
. The class must implement the following methods:
method | input parameters | return values | explanation | tournament time limit |
---|---|---|---|---|
__init__ | payoff_matrix (2×2 matrix of tuples), number_of_iterations (integer) | none | Instantiating a player object. The player will be always given the payoff_matrix . However, the number_of_iterations (i.e., number of rounds) may or may not be available. The method must, therefore, handle to be called with 1 or 2 parameters. That is, no error/exception must be raised when the method is called with 1 parameter only. The player typically saves these parameters and use them later for choosing an optimal strategy. More details on the format and usage of the payoff_matrix are to be found below. | 60 s |
move | none | False or True | Generating move. False means to stay silent (COOPERATE), True to betray (DEFECT). | 1 s |
record_last_moves | (my_last_move, opponent_last_move) (False or True) | none | The player receives last moves of both players (yours and opponent's). Both moves are represented by the Boolean type - False (=COOPERATE) or True (=DEFECT). The player can store the moves and use this information for later decision making. | 1 s |
The class - the player - should be identified by a short description in the form of the docstring. The description should explain the player's strategy. Example:
class MyPlayer: '''The player is very moody but mostly chooses COOPERATE.''' def __init__ # standard code follows
Player's A reward in case they play COOPERATE and the player B play DEFECT is coded as:
payoff_matrix[0][1][0]
Note: You can assume that the payoff matrix will always be symmetrical. The player, therefore, does not have to know if it is a player A or B. They share exactly the same opportunities and risks.
Simply put, the player's job is to play.
After implementing your player class, we recommend downloading the following code:
game.py
- game implementation
test_game.py
- code that can put two opponents against each other and let them play the game.
Read through these Python files and try to run them with your player (test_game.py puts two identical players against each other). You can modify the files at your will, of course.