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 dbTriCon():
4
'''
5
author: Daniel Bishop
6
This rule looks at the last 3 moves made by the opponent and chooses the most commonly made one.
7
If there are less than 3 moves made, it randomly chooses a move.
8
'''
9
def step(self, history, round):
10
if round < 3:
11
action = random.randint(0, 1)
12
else:
13
# Counter wasn't working for me
14
data = history[self.order^1]
15
last3 = data[round - 1] + data[round - 2] + data[round - 3]
16
if (last3 < 2):
17
action = 0
18
else:
19
action = 1
20
21
return action
22