Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
# Cooperating twice in a row has better payoff than cooperating once and then betraying
2
3
class ResponsiveTFTMod():
4
"""
5
Cooperate until opponent defects.
6
Then run TitForTat but throw the sequence every
7
three rounds to prevent oscillation.
8
Even with defect, beats others, low total score
9
"""
10
def step(self, history, round):
11
if round == 1:
12
action = 1
13
if round % 3 == 0:
14
action = 0
15
else:
16
# Check if the opponent has defected before - no forgivness version
17
opp_defect_count = 0
18
for opp_move in history[self.order^1]:
19
if opp_move == 0:
20
opp_defect_count += 1
21
22
if opp_defect_count > 0:
23
action = history[self.order^1][round - 1]
24
else:
25
action = 1
26
27
return action
28