diff --git a/__pycache__/contenders.cpython-310.pyc b/__pycache__/contenders.cpython-310.pyc new file mode 100644 index 0000000..1688457 Binary files /dev/null and b/__pycache__/contenders.cpython-310.pyc differ diff --git a/__pycache__/helper_functions.cpython-310.pyc b/__pycache__/helper_functions.cpython-310.pyc new file mode 100644 index 0000000..1d6e04e Binary files /dev/null and b/__pycache__/helper_functions.cpython-310.pyc differ diff --git a/contenders.py b/contenders.py new file mode 100644 index 0000000..6f0d7c7 --- /dev/null +++ b/contenders.py @@ -0,0 +1,38 @@ +import random + +random.seed() + +def my_winning_function(game_data,player_nr): + #game_data is the array of games so far, either empty(first round) or formatted like this: player_nr [[False, False],[False, False]] (2 rounds of only defections) + #player_nr is this players index, so whether they are the first(0) or the second(1) value in a round + opponent_nr=1-player_nr + #for ease of use this is index of the opponents value + choice=False + #this function should return either true(coorperate) or false(defect) + + #your cool code goes here + if len(game_data)>0: + #what to do if this is NOT the first round + choice=not game_data[len(game_data)-1][opponent_nr] + #this example always does the opposite of what the opponent did last round + else: + #what to do in the first round + choice=True + #this example starts with a cooperation + + #your cool code ended here + return choice + +def random_positive_leaner(game_data,player_nr): + #game_data is the array of games so far, either empty(first round) or formatted like this: player_nr [[False, False],[False, False]] (2 rounds of only defections) + #player_nr is this players index, so whether they are the first(0) or the second(1) value in a round + opponent_nr=1-player_nr + #for ease of use this is index of the opponents value + choice=False + #this function should return either true(coorperate) or false(defect) + + #your cool code goes here + if random.randint(0,10)<6: + choice=True + #your cool code ended here + return choice \ No newline at end of file diff --git a/helper_functions.py b/helper_functions.py new file mode 100644 index 0000000..4705fcc --- /dev/null +++ b/helper_functions.py @@ -0,0 +1,48 @@ +def analyze_results(game_data): + defect_str="X " + coorperate_str="O " + spacer_str="___"*len(game_data) + lines=["These are the results",spacer_str] + str1="Player 1: " + str2="Player 2: " + p_1_points=0 + p_2_points=0 + for i in game_data: + #visualize + if i[0]: + str1+=coorperate_str + elif not i[0]: + str1+=defect_str + if i[1]: + str2+=coorperate_str + elif not i[1]: + str2+=defect_str + #award points + if i[0] and i[1]: + p_1_points+=3 + p_2_points+=3 + elif i[0] and i[1]==False: + p_1_points+=5 + p_2_points+=0 + elif i[1] and i[0]==False: + p_1_points+=0 + p_2_points+=5 + elif i[0]==False and i[1]==False: + p_1_points+=1 + p_2_points+=1 + lines.append(str1+" Points:"+str(p_1_points)) + lines.append(str2+" Points:"+str(p_2_points)) + lines.append(spacer_str) + #print the results + for i in lines: + print(i) + +def play_game(games_array,func1,func2,how_many_times): + for i in range(how_many_times): + choice_1=func1(games_array,0) + choice_2=func2(games_array,1) + games_array.append([choice_1,choice_2]) + +def random_choice(game_data,player_nr): + ret=True + return ret \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..a382403 --- /dev/null +++ b/main.py @@ -0,0 +1,18 @@ + +#basic setup +#The prisoner's dilemma is a game theory thought +#experiment that involves two rational agents, each +#of whom can COORPERATE for mutual benefit or betray +#their partner ("defect") for individual reward. + +#imports +import helper_functions +import contenders +#vars +games=[] +#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +# Put YOUR function down below +#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + +helper_functions.play_game( games,contenders.random_positive_leaner , contenders.my_winning_function ,30) +helper_functions.analyze_results(games)