Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Repeated Prisoner's Dilemma

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 MoveOpponent’s MoveYour PenaltyOpponent’s Penalty
CC1010
CD500
DC050
DD3030

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_moven

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:

0

After 3 iterations:

3
C C
C D
D D

Round 1: you cooperated and the opponent cooperated. Round 2: you cooperated and the opponent defected. Round 3: you both defected.

Rules & Constraints

  1. Timeout: your program has 1000 ms per move, configurable by the instructor.

  2. No State: your program restarts for each move, so use the history to infer state.

  3. Valid Output: must output exactly C or D, any capitalization accepted. If the instructor runs with the Vietnamese symbol set, output H or P instead.

  4. No Communication: do not try to communicate with other processes.

  5. 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.