commit with optional input parameters

This commit is contained in:
taxicomics 2024-04-26 19:11:23 +00:00
parent 4cc2362dbb
commit 00a9debb4b
5 changed files with 34 additions and 8 deletions

View File

@ -36,3 +36,18 @@ def random_positive_leaner(game_data,player_nr):
choice=True
#your cool code ended here
return choice
def i_hate_certain_numbers(game_data,player_nr):
opponent_nr=1-player_nr
hated_numbers=[7,13,17,23]
#for ease of use this is index of the opponents value
choice=True
#this function should return either true(coorperate) or false(defect)
#your cool code goes here
round_nr=len(game_data)
if round_nr in hated_numbers:
choice=False
#your cool code ended here
return choice

View File

@ -1,3 +1,5 @@
import statistics
def analyze_results(game_data):
defect_str="X "
coorperate_str="O "
@ -46,15 +48,20 @@ def play_game(games_array,func1,func2,how_many_times):
def analyze_scores(score_table):
average_score_p_1=0
all_p1_scores=[]
all_p2_scores=[]
average_score_p_2=0
p1_sum=0
p2_sum=0
for i in score_table:
p1_sum+=i[0]
all_p1_scores.append(i[0])
p2_sum+=i[1]
all_p2_scores.append(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(str(average_score_p_1)+" AVG Player 1 Score |"+str(statistics.median(all_p1_scores))+" Median Player 1 Score")
print(str(average_score_p_2)+" AVG Player 2 Score |"+str(statistics.median(all_p2_scores))+" Median Player 1 Score")
#print(score_table)

16
main.py
View File

@ -13,15 +13,19 @@ import contenders
games=[]
#keeping track of the games scores for later analysis
scores=[]
nr_of_rounds=30
nr_of_games=300
nr_of_rounds=30#int(input("How many should be played in a game?"))
nr_of_games=300#int(input("How many games should be played?"))
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Put YOUR functions down below
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function1=contenders.random_positive_leaner
function2=contenders.random_positive_leaner
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Put YOUR function down below
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
function2=contenders.i_hate_certain_numbers
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=[]
print("Played "+str(nr_of_games)+ " games with "+str(nr_of_rounds)+" rounds each.")
print("(A huge disparity of the average and median could hint at special behaviour)")
helper_functions.analyze_scores(scores)