From 56f499c67ad3b5842599dec1494a9c8aa553f682 Mon Sep 17 00:00:00 2001 From: taxicomics <168220579+taxicomics@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:01:54 +0000 Subject: [PATCH] Inital Version --- __pycache__/contenders.cpython-310.pyc | Bin 0 -> 593 bytes __pycache__/helper_functions.cpython-310.pyc | Bin 0 -> 1245 bytes contenders.py | 38 +++++++++++++++ helper_functions.py | 48 +++++++++++++++++++ main.py | 18 +++++++ 5 files changed, 104 insertions(+) create mode 100644 __pycache__/contenders.cpython-310.pyc create mode 100644 __pycache__/helper_functions.cpython-310.pyc create mode 100644 contenders.py create mode 100644 helper_functions.py create mode 100644 main.py diff --git a/__pycache__/contenders.cpython-310.pyc b/__pycache__/contenders.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1688457b91c08cb16393aeb22d3d2b606366b265 GIT binary patch literal 593 zcmZWm!D<^Z5FJV5^}4l7pftoi7m8b`@1>MNN{=Rxoc6LTJ4!0ND=pHd!LUBH|B!2P z%rEV=C-)Od4;igfNa?`L=#54Xy%{%~Jps1sUvJM}CjdVqcx;lvC-(4)0|AK&GSF}% zZb1M^Qa>P*gf!x;NSwkV*>NYV%J}lHAs-a`F?)E=fkY>cU@J*(RSO+_7o^tc=N&vC zzMVrS=P-q>>eML^?(<@_+6iX(;$u8ph+b9N-eEtvC~BQk(H8xrsfvyEx%Jso*EG&* z+eVO-U!5uS9r!W7{rzTn<@`D{MXAH`#GAm4K72NnuIpl1I@@YXTzS`Q`sei~zcSVu zdy$`C+Ojpyj+i7o_7hO@oG^{D?IU%@5S+huYC)r9Z|Ugjh-;m8qP*xCi2bdG!DQ literal 0 HcmV?d00001 diff --git a/__pycache__/helper_functions.cpython-310.pyc b/__pycache__/helper_functions.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1d6e04e59e8e68ec42e036b21f16d2b715cb7444 GIT binary patch literal 1245 zcmZ8g&1(}u6rY*>-X^tZ{Q?gQ9yAnM6AD5pA}Hd;Sg;3Kls)Z6ci)hnmr;OREQ|{A$TRrWJMeH?Q_gDGSrJW^beq%`x3x85HAJZ$ z?$$2%Y7c&2ljr1pQ3pEU-d!T^Ye%!kq;_(@wWuAiP_%&V17csh2H_e6Skxg{5aF(4 zyjmk)X^#hB_q1=ge|Be$IB5|){J`W1pf=Vh4|t2hlT?c~CJI2dC-J-V;198lJ(D!Pqj8 z7)Y)rI0o7sF>LRdZQ5xKCFUye@%32a$TS}b>7wSv8(43Zq*A8y*ue|;TQ-O{$Hm8F zmge)MngB*_z>e6@#>FHPN&iwBn1Z&X3y>x#VJ;Gk`w&!xZ?^-N4CxlNf6FaUGfd@T z;gDc{=56~Rz}se;!5p&Tu?gF=WB~RyFtjC?u_ZdruNs literal 0 HcmV?d00001 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)