-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkato.py
76 lines (67 loc) · 2.24 KB
/
kato.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class KatoStrategy(object):
def __init__(self, random_state=None):
if random_state is None:
random_state = np.random.RandomState()
self.random_state = random_state
self.my_history = []
self.signals = []
def normal_action(self):
if len(self.signals)%3 == 1:
self.my_history.append(1)
return 1
elif len(self.signals)%3 == 2:
self.my_history.append(0)
return 0
else:
self.my_history.append(0)
return 0
def attack_action(self):
self.my_history.append(1)
return 1
def research1(self):
num_attack = 0.0
for i in self.signals:
if i == 1:
num_attack += 1.0
attack_percent = num_attack / (float(len(self.signals))+1)
if attack_percent >= 0.5:
return 1
else:
return 0
def research2(self):
for i in range(len(self.signals)-3):
if self.signals[-i-1] == 1 and self.signals[-i-2] == 1 and self.signals[-i-3] == 1:
return 1
else:
return 0
def research3(self):
num_attack = 20.0
for i in self.signals:
if i == 1:
num_attack += 1.0
attack_percent = num_attack / (float(len(self.signals))+1)
if attack_percent >= 0.2:
return 1
else:
return 0
def play(self):
research1_result = self.research1()
research3_result = self.research3()
if len(self.signals) <= 3:
if research1_result == 0:
return self.normal_action()
else:
return self.attack_action()
else:
prior_signal = self.signals[-1]
research2_result = self.research2()
if research2_result == 1:
return self.attack_action()
elif research1_result == 1:
return self.attack_action()
elif lem(self.myself) >= 20 and research3_result == 1:
return self.attack_action()
else:
return self.normal_action()
def get_signal(self, signal):
self.signals.append(1)