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 CheckAndChoose():
4
''' CheckAndChoose will cooperate 5 times, defect 5 times, then choose which had the best average score. '''
5
def step(self, history, round):
6
if round < 5:
7
action = 1 # Cooperate
8
elif round < 10:
9
action = 0 # Defect
10
elif round == 10:
11
outcome = [[[1,1], [5,0]], [[0,5], [3,3]]]
12
c_score = 0
13
d_score = 0
14
for i in range (0,10):
15
if i < 5:
16
score = outcome[history[0][i]][history[1][i]]
17
c_score += score[self.order]
18
19
else:
20
score = outcome[history[0][i]][history[1][i]]
21
d_score += score[self.order]
22
if c_score > d_score:
23
action = 1
24
else:
25
action = 0
26
27
else:
28
action = history[self.order][round - 1]
29
30
return action
31
32
33