parent
56f499c67a
commit
4cc2362dbb
|
@ -5,3 +5,5 @@ 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.
|
||||
|
||||
YOUR algorithm goes in the contender.py-file. You then go to main and pit it against another contender or itself.
|
Binary file not shown.
|
@ -36,6 +36,7 @@ def analyze_results(game_data):
|
|||
#print the results
|
||||
for i in lines:
|
||||
print(i)
|
||||
return p_1_points,p_2_points
|
||||
|
||||
def play_game(games_array,func1,func2,how_many_times):
|
||||
for i in range(how_many_times):
|
||||
|
@ -43,6 +44,17 @@ def play_game(games_array,func1,func2,how_many_times):
|
|||
choice_2=func2(games_array,1)
|
||||
games_array.append([choice_1,choice_2])
|
||||
|
||||
def random_choice(game_data,player_nr):
|
||||
ret=True
|
||||
return ret
|
||||
def analyze_scores(score_table):
|
||||
average_score_p_1=0
|
||||
average_score_p_2=0
|
||||
p1_sum=0
|
||||
p2_sum=0
|
||||
for i in score_table:
|
||||
p1_sum+=i[0]
|
||||
p2_sum+=i[1]
|
||||
|
||||
average_score_p_1=p1_sum/len(score_table)
|
||||
average_score_p_2=p2_sum/len(score_table)
|
||||
print(str(average_score_p_1))
|
||||
print(str(average_score_p_2))
|
||||
#print(score_table)
|
15
main.py
15
main.py
|
@ -9,10 +9,19 @@
|
|||
import helper_functions
|
||||
import contenders
|
||||
#vars
|
||||
#keeping track of the individual games
|
||||
games=[]
|
||||
#keeping track of the games scores for later analysis
|
||||
scores=[]
|
||||
nr_of_rounds=30
|
||||
nr_of_games=300
|
||||
function1=contenders.random_positive_leaner
|
||||
function2=contenders.random_positive_leaner
|
||||
#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)
|
||||
for i in range(nr_of_games):
|
||||
helper_functions.play_game( games,function1,function2,nr_of_rounds)
|
||||
scores.append(helper_functions.analyze_results(games))
|
||||
games=[]
|
||||
helper_functions.analyze_scores(scores)
|
Loading…
Reference in New Issue