Repeated Prisoner’s Dilemma¶
In this game, you will implement a strategy that plays against other students’
strategies over multiple iterations. Each round, both players simultaneously choose to either Cooperate, marked C,
or Defect, marked D.
The Game¶
The Prisoner’s Dilemma is a classic game theory problem. The payoff matrix below expresses penalties, and lower is better.
| Your Move | Opponent’s Move | Your Penalty | Opponent’s Penalty |
|---|---|---|---|
| C | C | 10 | 10 |
| C | D | 50 | 0 |
| D | C | 0 | 50 |
| D | D | 30 | 30 |
Goal: minimize your average penalty across all iterations and matches.
Submission Format¶
Submit a single Python file named <your_student_id>.py. Your program will be run
as a subprocess for each move. It must read game history from stdin and
output your move, C or D, to stdout.
Input Format¶
n
my_move1 opponent_move1
my_move2 opponent_move2
...
my_moven opponent_movenFirst line:
n, an integer, is the number of previous iterations.Next
nlines,my_move opponent_move, give the history from your perspective.Each move is either
CorD.
Output Format¶
Print a single character: C to cooperate or D to defect.
Example¶
First move with n = 0: no history yet, decide your opening move:
0After 3 iterations:
3
C C
C D
D DRound 1: you cooperated and the opponent cooperated. Round 2: you cooperated and the opponent defected. Round 3: you both defected.
Rules & Constraints¶
Timeout: your program has 1000 ms per move, configurable by the instructor.
No State: your program restarts for each move, so use the history to infer state.
Valid Output: must output exactly
CorD, any capitalization accepted. If the instructor runs with the Vietnamese symbol set, outputHorPinstead.No Communication: do not try to communicate with other processes.
Deterministic Evaluation: your strategy should handle any opponent.
If your program times out or produces invalid output, your submission is marked as broken and excluded from all remaining matches, and the incident is logged.
Tournament¶
Every submission plays every other submission in a round-robin tournament over multiple iterations per match. The final ranking is computed from the average penalty, with detailed results distributed after the tournament.