Skip to content

Instantly share code, notes, and snippets.

@SirLich
Last active January 5, 2024 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirLich/5cb1c1360d6a0182b4a55ed1a479f814 to your computer and use it in GitHub Desktop.
Save SirLich/5cb1c1360d6a0182b4a55ed1a479f814 to your computer and use it in GitHub Desktop.
PD: Rules

Prisoner's Dilemma Face Off!

Introduction

The Prisoner's Dilemma is a game theory thought experiment that involves two rational agents, each of whom can cooperate for mutual benefit or betray their partner ("defect") for individual reward. I will run a tournament, simulating this dilemma.

It's a hopelessly simple game, but I have a twist which should provide some enjoyment!

Example Bot

Here is an example bot, written in Python. In reality, you just need to implement start, play, and get_name. I will provide a JS equivalent when I find time. Here a link to the data structures used.

from manager import SetData, GameData

# Called when a round begins, so you can configure your strategy
# game_data contains the rules of the current game (e.g., how many rounds will be played)
def start(game_data: GameData):
	pass

# Called each round. Return 'true' (cooperate) or 'false' (defect)
# set_data contains stateful information about the current set (e.g., your current score)
def play(set_data : SetData):
	# Cooperate as long as we're winning
	return set_data.other_score > set_data.self_score

# Just return your bots name
def get_name() -> str:
	return "Greedy Bot"

The Tournament

The tournament will take place following these game rules. Each bot will play every other bot, including themselves. Points are accumulated for all matches, and the winner is the one with the most points. As the rules are known before-and (and due to the nature of the puzzle), it's likely that a fairly obtuse strategy will prevail, but do your best!

The Twist!

The twist is that I will run follow-up tournaments, with different game rules! I have a collection prepared, which promote differing strategies. The true winner will be the bot that can perform well in all of these scenarios. Take special consideration into the following:

  • win_bonus_points promotes aggression
  • cooperation_bonus promotes cooperation
  • defect_penalty discourages selfish play

Submission Guidelines

  • Submit a bot in Python (best), or JS
  • No funny business (internet connection, file access, malware)
  • You can submit multiple bots, as long as they're implementing unique strategies
  • I myself will be submitting a number of "simple" bots (e.g., Nice Bot, Mean Bot), but will remove these if somebody submits something identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment