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 TFTMemory():
4
""" TFTMemory is similar to TitForTat, but it calculates its move based on
5
all of its opponents' previous moves, instead of just the most recent one. """
6
def step(self, history, round):
7
if round == 0:
8
action = random.randint(0, 1)
9
else:
10
past = sum(history[self.order^1])
11
action = int(past > round / 2.0)
12
return action
13
14