diff --git a/prisoners_dilemma.py b/prisoners_dilemma.py index f2463e7..fd2dc28 100644 --- a/prisoners_dilemma.py +++ b/prisoners_dilemma.py @@ -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) diff --git a/team1.py b/team1.py index 972134e..9c2c60e 100644 --- a/team1.py +++ b/team1.py @@ -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. @@ -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): diff --git a/team10.py b/team10.py index 972134e..634b5f8 100644 --- a/team10.py +++ b/team10.py @@ -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') \ No newline at end of file diff --git a/team12.py b/team12.py index 972134e..afebb74 100644 --- a/team12.py +++ b/team12.py @@ -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') \ No newline at end of file + return 'b' \ No newline at end of file diff --git a/team14.py b/team14.py index 972134e..55b01be 100644 --- a/team14.py +++ b/team14.py @@ -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): diff --git a/team15.py b/team15.py new file mode 100644 index 0000000..77b4c63 --- /dev/null +++ b/team15.py @@ -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' \ No newline at end of file diff --git a/team16.py b/team16.py new file mode 100644 index 0000000..cda52f7 --- /dev/null +++ b/team16.py @@ -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' diff --git a/team17.py b/team17.py new file mode 100644 index 0000000..c7c4ac0 --- /dev/null +++ b/team17.py @@ -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' \ No newline at end of file diff --git a/team18.py b/team18.py new file mode 100644 index 0000000..88fb01e --- /dev/null +++ b/team18.py @@ -0,0 +1,22 @@ +#### +# 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 = 'Opposite' # Only 10 chars displayed. +strategy_name = 'Opposite of T4T' +strategy_description = 'Opposite of T4T' + +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 colluded last turn + elif their_history[-1] == 'c': + return 'b' + #collude if opponent betrayed last turn + else: + return 'c' \ No newline at end of file diff --git a/team19.py b/team19.py new file mode 100644 index 0000000..6a6b9ae --- /dev/null +++ b/team19.py @@ -0,0 +1,19 @@ +#### +# 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 = 'GoPsycho' # Only 10 chars displayed. +strategy_name = 'Be nice at first, then always betray' +strategy_description = 'Be nice at first, then always betray' + +def move(my_history, their_history, my_score, their_score): + #always collude if it is before turn 100 + if len(my_history) < 80: + return 'c' + #always betray starting at turn 80 + else: + return 'b' \ No newline at end of file diff --git a/team3.py b/team3.py index 972134e..bae832b 100644 --- a/team3.py +++ b/team3.py @@ -1,68 +1,21 @@ -#### -# 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 = '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 = 'MemeLord' # Only 10 chars displayed. +strategy_name = 'Random Choices Unless Certain Circumstance' +strategy_description = 'This strategy randomly picks b or c unless in certain situations.' 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]. + import random - # 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') \ No newline at end of file + if random.random < 0.33 and len(my_history) == 0: + return 'c' + elif random.random > 0.33 and random.random < 0.66 and len(my_history) == 0: + return 'b' + elif random.random > 0.66 and their_history == 'c' and len(my_history) == 0: + return 'b' + elif random.random > 0.66 and their_history == 'b' and len(my_history) == 0: + return random.choice(['c','b']) + + if random.random < 0.67 and len(my_history) > 0: + return random.choice(['c','b']) + elif len(my_history) > 0 and random.random > 0.67: + return 'b' \ No newline at end of file diff --git a/team7.py b/team7.py index 972134e..25ea599 100644 --- a/team7.py +++ b/team7.py @@ -6,63 +6,33 @@ # 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 = 'Hoffman' # Only 10 chars displayed. +strategy_name = 'Curved Response' +strategy_description = "Choice dependent on opponent's multiple previous responses." 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 + if len(their_history) == 0: + return 'c' + elif len(their_history) == 1: + return 'c' + elif len(their_history) == 2: + return 'c' + elif len(their_history) >= 3: + if their_history[-3:] == 'ccc': + return 'c' + elif their_history[-3:] == 'bbb': + return 'b' + elif their_history[-3:] == 'ccb': + return 'c' + elif their_history[-3:] == 'bbc': + return 'b' + elif their_history[-3:] == 'cbb': + return 'b' + elif their_history[-3:] == 'bcc': + return 'c' + elif their_history[-3:] == 'bcb': + return 'b' + elif their_history[-3:] == 'cbc': + return 'c' 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') \ No newline at end of file + return 'c' \ No newline at end of file diff --git a/team9.py b/team9.py index 972134e..01ebbd2 100644 --- a/team9.py +++ b/team9.py @@ -1,68 +1,14 @@ -#### -# 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 = 'Vindictish' +strategy_name = 'I shall forgeev' +strategy_description = 'meanie gets meanie' -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?' - 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 + if len(my_history) == 0: + return 'c' + elif 'b' not in their_history(-5): + return 'c' + elif 'b' in their_history: + return 'b' 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') \ No newline at end of file + return 'c' + \ No newline at end of file