Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
import random
2
class SPTFT():
3
''' Suspicious, Probing TitForTat will replicate its opponent's last move, start by defecting, and occasionally make a random move '''
4
def step(self, history, round):
5
if round == 0:
6
action = 0
7
8
elif random.random() < 0.125:
9
action = random.choice([0,1])
10
else:
11
action = history[self.order^1][round - 1]
12
# ^ is the bitwise XOR operator, for easy switching from 0 to 1.
13
return action
14
15