Inspired by this script, this project explores the Iterated Prisoner's Dilemma through a dynamic and evolutionary simulation.
- Configurable parameters: You can now adjust payoffs (R, P, T, S), the number of agents, the percentage of new agents per generation, the number of generations, the number of games per generation, and the mutation value using sliders in the interface.
- Strategy legend: The color legend for agent strategies has been improved and clarified.
- Visualization: Choose between viewing the population table or the strategy graph using radio buttons.
- Top agents: The top 3 agents in the current generation are displayed.
- Mutation and cloning: The logic for agent mutation and cloning has been optimized for more realistic simulation.
In tabular representation, each row represents an iteration (top to bottom), and each rectangle represents an agent. Agents are sorted left to right by score. The color of each rectangle encodes the agent's strategy:
- Green: Always Cooperate – agents always cooperate.
- Red: Always Defect – agents always defect.
- Blue: Tit-for-Tat – agents mirror the opponent's last move.
- Black: Grim Trigger – agents cooperate until betrayed, then always defect.
- Cyan: Generous Tit-for-Tat – agents forgive occasional defections.
- Purple: Pavlov – agents repeat successful actions, switch after loss.
- Gray: Random/Unclassified – agents use a random strategy or agents do not fit any specific strategy.
In graph mode, the evolution of strategies is shown over generations. Each color in the graph represents the prevalence of a specific strategy type in the population, allowing you to observe how strategies compete and change over time. This visualization helps to identify which strategies dominate, persist, or disappear as the simulation progresses.
You can try the simulation here:
👉 https://adebiasi.github.io/PrisonersDilemma/