Hi,
Your have to (1) choose an encoding that can express the kinds of memory‑based strategies (TitforTat, Grim, etc.), and (2) write a decoder that turns each chromosome into a callable strategy function.
You can follow the roadmap below to get started on iterative prisoners dilemma startegy using genetic algorithm in MATLAB:
- Chromosome design – Use a 5‑bit vector [g1 g2 g3 g4 g5] where g1= first move and g2–g5= moves for CC,CD,DC,DD (previous round).
- Decoder – A tiny function consults the chromosome to decide the next move. If there is no history yet, returng₁. Otherwise map the last round’s outcome to one of the remaining four genes and return that gene value. Decoder never changes.
- Define the payoff environment – Select the Prisoner’s Dilemma payoff numbers (e.g. Temptation=5, Reward=3, Punishment=1) and a game length (e.g. 150 rounds). All candidates will be evaluated under exactly the same conditions.
- Define the fitness function – For a given chromosome; Run a match against each benchmark opponent, summing your pay‑off each round. Average those pay‑offs.Return the negative of that average (MATLAB’s "ga" minimises the objective, so negating the score converts “high payoff is good” into “low objective is good”).
- Genetic loop – Initialise a random population of chromosomes; then for each generation: evaluation → selection → crossover → mutation (small bit‑flips) → next population.
- Stop condition – When best score plateaus or after a set number of generations.
- Read result – Inspect the best 5‑bit vector; it encodes a full memory‑1 strategy (e.g.,11010 = Tit‑for‑Tat, 11000 = Grim).
Here is more information on MATLAB's function"ga":
Hope this helps!
