-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterated.py
89 lines (71 loc) · 2.04 KB
/
iterated.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright Florentin Schleuß 2020-2022. Licensed under
# the EUPL-1.2 or later
import axelrod as axl
from tools import run_tournament
import io
from datetime import datetime
def pretty_print(no, match):
# Calculate total score
total_score = sum(list(match.final_score()))
# Pretty print
pretty = "Playing Match No. " + str(no) + " (length: " + str(match.turns) + ")\n"
pretty += "Players: "
pretty += str(match.players) + "\n"
pretty += "Winner: "
pretty += str(match.winner()) + "\n"
pretty += "Final Scores: "
pretty += str(match.final_score()) + "\n"
pretty += "Total Score: "
pretty += str(total_score) + "\n"
pretty += "Sparklines: (█ = Cooperation, = Defection)\n"
with io.open("iterated_results.txt", "a") as file:
file.write(pretty)
file.write(match.sparklines(c_symbol="█", d_symbol=" ") + "\n\n\n")
"""
Reset output file
"""
with io.open("iterated_results.txt", "w") as file:
file.write(datetime.now().strftime("%d/%m/%Y %H:%M:%S") + "\n\n")
match_length = 80
"""
Match One: Defector vs Cooperator
"""
players = [axl.Defector(), axl.Cooperator()]
match = axl.Match(players, match_length)
match.play()
pretty_print(1, match)
"""
Match Two: Tit For Tat vs Cooperator
"""
players = [axl.Cooperator(), axl.TitForTat()]
match = axl.Match(players, match_length)
match.play()
pretty_print(2, match)
"""
Match Three: Tit For Tat vs Defector
"""
players = [axl.Defector(), axl.TitForTat()]
match = axl.Match(players, match_length)
match.play()
pretty_print(3, match)
"""
Match Four: TitForTat vs CyclerCCD
"""
players = [axl.TitForTat(), axl.CyclerCCD()]
match = axl.Match(players, match_length)
match.play()
pretty_print(4, match)
"""
Match Five: Defector vs Cooperator
"""
players = [axl.CyclerCCD(), axl.Grudger()]
match = axl.Match(players, match_length)
match.play()
pretty_print(5, match)
"""
Match Six: Tit for Tat vs GoByMajority Hard
"""
players = [axl.TitForTat(), axl.GoByMajority(soft=False)]
match = axl.Match(players, match_length)
match.play()
pretty_print(6, match)