Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions prisoners_dilemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,26 @@
import team0, team1, team2, team3, team4
import team5, team6, team7, team8, team9
import team10, team11, team12, team13, team14
import team15, team16, team17, team18, team19
betray = example1
collude = example0

modules = [example0, example1, example2, example3, example4, example5, example6, example7,
team0, team1, team2, team3, team4, team5, team6, team7, team8, team9, team10,
team11, team12, team13, team14]
teams=[team0,team1,team2,team3,team4,team5,team6,team7,team8,team9]
team11, team12, team13, team14, team15, team16, team17, team18,team19]

##### Change this team list to change what strategies are included ########
teams=[team0,team1,team2,team3,team4,team5,team6,team7,team8,team9,team10,team11,team12,team13,team14,team15,team16,team17,team18,team19]
##########################################################################
# You should try a variety of different mixes of teams to see what happens
# in different situations. The success of your program depends on what types
# of other programs you are playing against!
###########################################################################
# examples of how to add more than one of a strategy:
# teams = [team0, team1, team2] + 4*[team3] + 4*[team6]
# teams = [team1, team1, team1, team2, team2, team2, team7]
###########################################################################

for module in modules:
reload(module)
print ('reloaded',module)
Expand Down
29 changes: 19 additions & 10 deletions team1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
# move: A function that returns 'c' or 'b'
####

team_name = 'The name the team gives to itself' # Only 10 chars displayed.
strategy_name = 'The name the team gives to this strategy'
strategy_description = 'How does this strategy decide?'
team_name = 'KalebAustn' # Only 10 chars displayed.
strategy_name = 'Random, then tit 2 per tat'
strategy_description = 'random choice, tit for 2 tat'

def move(my_history, their_history, my_score, their_score):
''' Arguments accepted: my_history, their_history are strings.
my_score, their_score are ints.

Make my move.
Returns 'c' or 'b'.
'''
import random
#ourlist = ['c', 'c', 'b']
if len(my_history) == 0:
return random.choice(['c', 'b', 'c'])
if len(my_history) == 1:
return random.choice(['c', 'b', 'c'])
elif their_history[-1] == 'b':
return 'b'
elif my_history[-2] == 'cb' or 'Cb' or 'CB' or 'cB':
return 'b'
elif my_history[-2] == 'bb':
return 'c'
else:
return random.choice(['c', 'c', 'b'])

# my_history: a string with one letter (c or b) per round that has been played with this opponent.
# their_history: a string of the same length as history, possibly empty.
Expand All @@ -26,7 +34,8 @@ def move(my_history, their_history, my_score, their_score):
# Analyze my_history and their_history and/or my_score and their_score.
# Decide whether to return 'c' or 'b'.

return 'c'
#return 'b'



def test_move(my_history, their_history, my_score, their_score, result):
Expand Down
113 changes: 58 additions & 55 deletions team10.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,66 @@
# move: A function that returns 'c' or 'b'
####

team_name = 'The name the team gives to itself' # Only 10 chars displayed.
strategy_name = 'The name the team gives to this strategy'
strategy_description = 'How does this strategy decide?'
team_name = 'Sow-awse' # Only 10 chars displayed.
strategy_name = 'Chicken'
strategy_description = "Basically you add the sow-ace to the chicken..."

def move(my_history, their_history, my_score, their_score):
''' Arguments accepted: my_history, their_history are strings.
my_score, their_score are ints.

Make my move.
Returns 'c' or 'b'.
'''
#peter and my, "Code" for recognizing eachother
partner = "False"
if len(my_history) == 0:
return "c"
if len(my_history) == 1:
return "b"
if len(my_history) == 2:
return "b"
if len(my_history) == 3:
return "c"
if len(my_history) == 4:
return "c"
if len(my_history) == 5:
return "b"
if len(my_history) == 6:
return "c"
if len(my_history) == 7:
return "c"
if len(my_history) == 8:
return "c"
if len(my_history) == 9:
return "b"
if len(my_history) == 10:
return "c"
if len(my_history) == 11:
if my_history == their_history:
return "c"
partner = "True"
else:
partner = "False"
if their_history[-1] == "b":
return "b"
#if they squeal on me, I squeal back, the worst that could happen is lose 250
else:
return "b"
#if they dont squeal, I squeal. I get 100 points :)
if len(my_history) >= 12:
if partner == "True":
return "c"
else:
#just some possible strategys and counters
if their_history[1:10] == my_history[0:9]:
return "c"
elif their_history == len(their_history) * "b":
return "b"
elif their_history[0:4] == "cbcb" or their_history[0:4] == "bcbc":
return their_history[-1]
elif their_history[-1] == "b":
return "b"
#if they squeal on me, I squeal back, the worst that could happen is lose 250
else:
return "b"
#if they dont squeal, I squeal. I get 100 points :)
if len(my_history) == 134:
return "c"

# my_history: a string with one letter (c or b) per round that has been played with this opponent.
# their_history: a string of the same length as history, possibly empty.
# The first round between these two players is my_history[0] and their_history[0].
# The most recent round is my_history[-1] and their_history[-1].

# Analyze my_history and their_history and/or my_score and their_score.
# Decide whether to return 'c' or 'b'.

return 'c'


def test_move(my_history, their_history, my_score, their_score, result):
'''calls move(my_history, their_history, my_score, their_score)
from this module. Prints error if return value != result.
Returns True or False, dpending on whether result was as expected.
'''
real_result = move(my_history, their_history, my_score, their_score)
if real_result == result:
return True
else:
print("move(" +
", ".join(["'"+my_history+"'", "'"+their_history+"'",
str(my_score), str(their_score)])+
") returned " + "'" + real_result + "'" +
" and should have returned '" + result + "'")
return False

if __name__ == '__main__':

# Test 1: Betray on first move.
if test_move(my_history='',
their_history='',
my_score=0,
their_score=0,
result='b'):
print 'Test passed'
# Test 2: Continue betraying if they collude despite being betrayed.
test_move(my_history='bbb',
their_history='ccc',
# Note the scores are for testing move().
# The history and scores don't need to match unless
# that is relevant to the test of move(). Here,
# the simulation (if working correctly) would have awarded
# 300 to me and -750 to them. This test will pass if and only if
# move('bbb', 'ccc', 0, 0) returns 'b'.
my_score=0,
their_score=0,
result='b')
62 changes: 4 additions & 58 deletions team12.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,9 @@
# move: A function that returns 'c' or 'b'
####

team_name = 'The name the team gives to itself' # Only 10 chars displayed.
strategy_name = 'The name the team gives to this strategy'
strategy_description = 'How does this strategy decide?'
team_name = 'TAB' # Only 10 chars displayed.
strategy_name = 'Betrayal'
strategy_description = 'Always betray'

def move(my_history, their_history, my_score, their_score):
''' Arguments accepted: my_history, their_history are strings.
my_score, their_score are ints.

Make my move.
Returns 'c' or 'b'.
'''

# my_history: a string with one letter (c or b) per round that has been played with this opponent.
# their_history: a string of the same length as history, possibly empty.
# The first round between these two players is my_history[0] and their_history[0].
# The most recent round is my_history[-1] and their_history[-1].

# Analyze my_history and their_history and/or my_score and their_score.
# Decide whether to return 'c' or 'b'.

return 'c'


def test_move(my_history, their_history, my_score, their_score, result):
'''calls move(my_history, their_history, my_score, their_score)
from this module. Prints error if return value != result.
Returns True or False, dpending on whether result was as expected.
'''
real_result = move(my_history, their_history, my_score, their_score)
if real_result == result:
return True
else:
print("move(" +
", ".join(["'"+my_history+"'", "'"+their_history+"'",
str(my_score), str(their_score)])+
") returned " + "'" + real_result + "'" +
" and should have returned '" + result + "'")
return False

if __name__ == '__main__':

# Test 1: Betray on first move.
if test_move(my_history='',
their_history='',
my_score=0,
their_score=0,
result='b'):
print 'Test passed'
# Test 2: Continue betraying if they collude despite being betrayed.
test_move(my_history='bbb',
their_history='ccc',
# Note the scores are for testing move().
# The history and scores don't need to match unless
# that is relevant to the test of move(). Here,
# the simulation (if working correctly) would have awarded
# 300 to me and -750 to them. This test will pass if and only if
# move('bbb', 'ccc', 0, 0) returns 'b'.
my_score=0,
their_score=0,
result='b')
return 'b'
42 changes: 23 additions & 19 deletions team14.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@
# move: A function that returns 'c' or 'b'
####

team_name = 'The name the team gives to itself' # Only 10 chars displayed.
strategy_name = 'The name the team gives to this strategy'
strategy_description = 'How does this strategy decide?'

team_name = 'GOURD'
strategy_name = 'JusticeStrategy'
strategy_description = 'Collude until enemy betrays, then betray every time with a 50 percent chance to forgive.'
class betrayed:
pass
#betrayed.betrayed- if betrayed, betray every time, but chance to forgive
def move(my_history, their_history, my_score, their_score):
''' Arguments accepted: my_history, their_history are strings.
my_score, their_score are ints.

Make my move.
Returns 'c' or 'b'.
'''

# my_history: a string with one letter (c or b) per round that has been played with this opponent.
# their_history: a string of the same length as history, possibly empty.
# The first round between these two players is my_history[0] and their_history[0].
# The most recent round is my_history[-1] and their_history[-1].

# Analyze my_history and their_history and/or my_score and their_score.
# Decide whether to return 'c' or 'b'.
import random

return 'c'
if len(their_history) == 0:
betrayed.betrayed = False
return 'c'
elif their_history[-1] == 'b':
betrayed.betrayed = True
return 'b'
elif their_history [-1] == 'c' and betrayed.betrayed == True:
if random.random() > .5:
betrayed.betrayed == False
return "c"
else:
return "b"
elif betrayed.betrayed == True:
return 'b'
else:
return 'c'


def test_move(my_history, their_history, my_score, their_score, result):
Expand Down
27 changes: 27 additions & 0 deletions team15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
####
# Each team's file must define four tokens:
# team_name: a string
# strategy_name: a string
# strategy_description: a string
# move: A function that returns 'c' or 'b'
####

team_name = 'Forgiving' # Only 10 chars displayed.
strategy_name = 'T4T but occasionally forgives'
strategy_description = 'T4T but occasionally forgives'

def move(my_history, their_history, my_score, their_score):
import random
#collude on first turn
if len(their_history)==0:
return 'c'
elif their_history[-1] == 'b':
#Betray 90% of the time after being betrayed
if random.random() < 0.90:
return 'b'
#Collude 10% of the time after being betrayed
else:
return 'c'
#collude if opponent colluded last turn
else:
return 'c'
25 changes: 25 additions & 0 deletions team16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
####
# Each team's file must define four tokens:
# team_name: a string
# strategy_name: a string
# strategy_description: a string
# move: A function that returns 'c' or 'b'
####

team_name = 'SneakyT4T' # Only 10 chars displayed.
strategy_name = 'T4T but occasionally betrays randomly'
strategy_description = 'T4T but occasionally betrays randomly'

def move(my_history, their_history, my_score, their_score):
import random
if len(their_history)==0:
return 'c'
elif their_history[-1] == 'b':
return 'b'
else:
#Collude 90% of the time after opponent colludes
if random.random() < 0.90:
return 'c'
#Betray 10% of the time after opponent colludes
else:
return 'b'
23 changes: 23 additions & 0 deletions team17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
####
# Each team's file must define four tokens:
# team_name: a string
# strategy_name: a string
# strategy_description: a string
# move: A function that returns 'c' or 'b'
####

team_name = 'Retal-c' # Only 10 chars displayed.
strategy_name = 'Benevolent Retaliator'
strategy_description = 'Benevolent Retaliator'

def move(my_history, their_history, my_score, their_score):
#collude on the first turn
if len(their_history)==0:
return 'c'
#betray if opponent successfully betrayed last turn
#(this does not include cases when both players betrayed)
elif their_history[-1] == 'b' and my_history[-1] == 'c':
return 'b'
#otherwise collude
else:
return 'c'
Loading