Inital Version

This commit is contained in:
taxicomics 2024-04-26 18:01:54 +00:00
parent 7a9c8d0e45
commit 56f499c67a
5 changed files with 104 additions and 0 deletions

Binary file not shown.

Binary file not shown.

38
contenders.py Normal file
View File

@ -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

48
helper_functions.py Normal file
View File

@ -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

18
main.py Normal file
View File

@ -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)