diff --git a/README.md b/README.md index a382087..7d8d0ea 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/__pycache__/helper_functions.cpython-310.pyc b/__pycache__/helper_functions.cpython-310.pyc index 1d6e04e..76b0382 100644 Binary files a/__pycache__/helper_functions.cpython-310.pyc and b/__pycache__/helper_functions.cpython-310.pyc differ diff --git a/helper_functions.py b/helper_functions.py index 4705fcc..d2a3728 100644 --- a/helper_functions.py +++ b/helper_functions.py @@ -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 \ No newline at end of file +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) \ No newline at end of file diff --git a/main.py b/main.py index a382403..508f64a 100644 --- a/main.py +++ b/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) \ No newline at end of file