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
3
class Flipper():
4
''' Flipper will alternate defections and cooperations, selecting the first
5
move randomly.
6
'''
7
def step(self, history, round):
8
if round == 0:
9
action = random.randint(0, 1)
10
else:
11
action = history[self.order][round - 1]^1
12
# ^ is the bitwise XOR operator, for easy switching from 0 to 1.
13
return action
14