====== B - Player specification ====== Here, you will find a detailed description of the required player's functionalities. ===== Files to submit ===== **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. ===== MyPlayer class and its methods ===== 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'' (2x2 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 | ===== Descriptive string ===== 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 ===== Payoff_matrix ===== * The payoff matrix will be represented as a two-dimensional array of tuples (2-tuples, pairs). You will need 3 indices to correctly reference it: * **Index 0**: Player's A move: 0 - 'COOPERATE', 1 - 'DEFECT'. * **Index 1**: Player's B move: 0 - 'COOPERATE', 1 - 'DEFECT'. * **Index 2**: 0 - Player's A reward, 1 - Player's B reward. 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. ==== Payoff matrix example ==== {{:courses:be5b33prg:homework:regular:06_prisoners_dilemma:prisoner_s_dilemma_table.png?direct|}} Python representation of the same payoff matrix: payoff_matrix = ( ((4,4),(1,6)) , ((6,1),(2,2)) ) ===== It is forbidden ===== * to write to a hard-drive. All you need to store in-between move, store in the (RAM) memory. * to connect to other computers, processes, etc. * to search the hard-drive * to dishonourable influence opponent's decision making * ... Simply put, the player's job is to play. ===== Download ===== After implementing your player class, we recommend downloading the following [[https://gitlab.fel.cvut.cz/RPH-student-materials/pd|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.