Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
import numpy as np
2
3
class Patrick():
4
''' TitForTat with random defection of 20% added in '''
5
def step(self, history, round):
6
if round == 0:
7
action = 1
8
else:
9
opponent = history[self.order^1][round - 1]
10
random_meanness = np.random.random() < .20
11
12
if (random_meanness):
13
action = 0
14
else:
15
action = opponent
16
17
return action
18