• Stars
    star
    205
  • Rank 191,264 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Watch This Place's awesome video about iterated Prisoner's Dilemma for context! https://www.youtube.com/watch?v=BOvAbjfJ0x0

PrisonersDilemmaTournament

This is my CS 269i class project.

Watch This Place's awesome videos about iterated Prisoner's Dilemma for context!

https://www.youtube.com/watch?v=t9Lo2fgxWHw

https://www.youtube.com/watch?v=BOvAbjfJ0x0

Nicky Case's "The Evolution of Trust" is also super fascinating, but it's not necessary to understand this project: https://ncase.me/trust/

How this works: When you run code/prisonersDilemma.py, it will search through all the Python strategy files in code/exampleStrats. Then, it will simulate "Iterated Prisoner's Dilemma" with every possible pairing. (There are (n choose 2) pairings.) After all simulations are done, it will average each strategies' overall score. It will then produce a leaderboard of strategies based on their average performance, and save it to results.txt.

If you'd like to add your own strategy, all you have to do is create a new .py file in the code/exampleStrats folder that follows the same format as the others. Then, when you run code/prisonersDilemma.py, it should automatically include your strategy into the tournament!

Details

Payout Chart Player A cooperates Player A defects
Player B cooperates A: +3, B: +3 A: +5, B: +0
Player B defects A: +0, B: +5 A: +1, B: +1

In this code, 0 = 'D' = defecting, and 1 = 'C' = cooperating.


Strategy functions take in two parameters, 'history' and 'memory', and output two values: 'moveChoice' and 'memory'. 'history' is a 2*n numpy array, where n is the number of turns so far. Axis one corresponds to "this player" vs "opponent player", and axis two corresponds to what turn number we're on. For example, it might have the values

 [[0 0 1]       a.k.a.    D D C
  [1 1 1]]      a.k.a.    C C C

In this case, there have been 3 turns, we have defected twice then cooperated once, and our opponent has cooperated all three times.

'memory' is a very open-ended parameter that can takes on any information that should be retained, turn-to-turn. Strategies that don't need memory, like Tit-for-tat, can simply return None for this variable. If you want to keep track of being 'wronged', like grimTrigger.py, you can set memory to True or False. If you have an extremely complicated strategy, you have make 'memory' store a list of arbitrarily many varibles!

For the outputs: the first value is just the move your strategy chooses to make, with 0 being defect and 1 being cooperate. The second value is any memory you'd like to retain into the next iteration. This can be 'None'.


Each pairing simulation runs for this many turns:

200-40*np.log(random.random())

This means each game is guaranteed to be at least 200 turns long. But then, for every turn after the 200th, there is an equal probability that the game ends. The probability is very low, so there should be no strategizing to defect on the very last turn consequence-free.

More Repositories

1

jumpcutter

Automatically edits vidx. Explanation here: https://www.youtube.com/watch?v=DQ8orIurGxw
Python
3,073
star
2

lazykh

Source code for the automatic lip-syncing project described in this video! https://www.youtube.com/watch?v=y3B8YqeLCpY
Python
327
star
3

alignedCelebFaces

Better version of my face editing tool. Explanation video here: https://www.youtube.com/watch?v=NTlXEJjfsQU
Python
177
star
4

videoToVoice

takes in a sequence of lip images, and predicts the phonemes being said.
Python
121
star
5

evolutionSteer

Evolution simulator of creatures learning how to steer towards food pellets better and better.
Processing
94
star
6

VirusGame

Watch here for information about this project: https://www.youtube.com/watch?v=o1IheoDRdGE
Processing
88
star
7

yoyleCityWords

This is a city renderer I created in 2013. It's all hacked together and very slow, so watch out. Explanation video here: https://www.youtube.com/watch?v=y0nsXiI_I9c
Processing
81
star
8

rapLyrics

"Source code" for this video: https://www.youtube.com/watch?v=a0EyfdQ0QTQ I'm only adding 1 file here bc I didn't actually code that much.
Python
75
star
9

recordTrimEdit

Records audio, trims it, and allows you to edit it, all in one fell swoop.
Python
70
star
10

AbacabaCOVID19

A dumping ground of all my COVID-19 visualizations posted here: https://www.youtube.com/user/1abacaba1/videos
Processing
55
star
11

neuralNetworkLanguageDetection

The first neural network I've ever made to improve itself with gradient descent, made on Nov. 20, 2016
Processing
47
star
12

WordleEdit

Multiplayer game that plays a version of Wordle where players can edit their own words as they go. Runs as a Discord bot!
JavaScript
37
star
13

5b

Flash game I developed in early 2013, first announced in this YouTube video: https://www.youtube.com/watch?v=emDpKog8v6w
ActionScript
25
star
14

SpiderEvoSim

spiders
Processing
22
star
15

AbacabaTutorialDrawer

Tutorial Bar graph drawer in Processing. Watch: https://www.youtube.com/watch?v=XCiKO-Qysqk
Processing
19
star
16

rubiksChess

Rubik's Chess. You know the one.
JavaScript
17
star
17

caryCompressionMIDICSV

Watch this video for explanation: https://www.youtube.com/watch?v=SacogDL_4JU
Processing
16
star
18

testRepository

I don't know what I'm doing. AAAAAA
15
star
19

BFDIA7intro

My source code to generate the intro to BFDIA 7: https://www.youtube.com/watch?v=kTcfak9R-ok
Processing
15
star
20

yoyleCity

Here's the original 2013 source code for drawing Yoyle City, which appears at 2:27 in https://www.youtube.com/watch?v=RZB7nTzSl3g&t=207s
Processing
13
star
21

riseGuys

An AmazingRace-inspired version of Doodle Jump I started in 2012, continued in 2020, but never finished.
ActionScript
12
star
22

WCA_SAC

Creates a stacked-area-chart of the Top 100 WCA results, year by year.
Python
12
star
23

chineseCharacterConverter

We're trying to convert traditional Chinese characters to simplified ones.
Python
11
star
24

eclipser

It's the eclipser. Video explanation: https://www.youtube.com/watch?v=NDUh56GAEgM
Processing
9
star
25

HOTSprediction

Predicts the outcomes of Heroes of the Storm games, but not very well. Idea by Adrian
Processing
8
star
26

EvolutionSimulator2D

This is my old evolution simulator from July 2016. I guess that's not THAT long ago...
8
star
27

Bridge_Crossing

Tool to visualize solutions to a puzzle in 3D, as described in this video: https://www.youtube.com/watch?v=y_ii8QT7zsk
Processing
7
star
28

dump

dump
7
star
29

celebrityFaces

My CS229 final project
Python
6
star
30

bfdia10chant

Generates the images seen in BFDIA 10 (https://youtu.be/lcObRZOVdRM?t=887)
Processing
5
star
31

ewow_public_tools

Various tools for EWOW! (like word counter)
Python
5
star
32

Non_Transitive_Dice

video: https://www.youtube.com/watch?v=-fWcB7TAqLE&feature=youtu.be
Processing
4
star
33

Team-11

JavaScript
3
star
34

hthplotter

Head-to-head ao5 plotter for speedcubing. (Check YouTube video linked in readme)
HTML
2
star
35

arduinoLEDs

This comes from one of my video
Arduino
1
star
36

compress_image_sequence

Searches the specified folder for image sequences, then uses ffmpeg to convert them into .mp4's, and then (optionally) deletes the original images.
Python
1
star
37

ewow_elim_sim

Runs simulations to see how many EWOW contestants will be left at each round, on average! (Monte Carlo search)
Python
1
star