1
- from axelrod .actions import Actions
1
+ from axelrod .actions import Actions , Action
2
2
from axelrod .player import Player
3
3
from axelrod ._strategy_utils import detect_cycle
4
4
5
+ from typing import List , Tuple
6
+
5
7
C , D = Actions .C , Actions .D
6
8
7
9
@@ -19,7 +21,7 @@ class DefectorHunter(Player):
19
21
'manipulates_state' : False
20
22
}
21
23
22
- def strategy (self , opponent ) :
24
+ def strategy (self , opponent : Player ) -> Action :
23
25
if len (self .history ) >= 4 and len (opponent .history ) == opponent .defections :
24
26
return D
25
27
return C
@@ -39,13 +41,13 @@ class CooperatorHunter(Player):
39
41
'manipulates_state' : False
40
42
}
41
43
42
- def strategy (self , opponent ) :
44
+ def strategy (self , opponent : Player ) -> Action :
43
45
if len (self .history ) >= 4 and len (opponent .history ) == opponent .cooperations :
44
46
return D
45
47
return C
46
48
47
49
48
- def is_alternator (history ) :
50
+ def is_alternator (history : List [ Action ]) -> bool :
49
51
for i in range (len (history ) - 1 ):
50
52
if history [i ] == history [i + 1 ]:
51
53
return False
@@ -66,11 +68,11 @@ class AlternatorHunter(Player):
66
68
'manipulates_state' : False
67
69
}
68
70
69
- def __init__ (self ):
71
+ def __init__ (self ) -> None :
70
72
super ().__init__ ()
71
73
self .is_alt = False
72
74
73
- def strategy (self , opponent ) :
75
+ def strategy (self , opponent : Player ) -> Action :
74
76
if len (opponent .history ) < 6 :
75
77
return C
76
78
if len (self .history ) == 6 :
@@ -100,11 +102,11 @@ class CycleHunter(Player):
100
102
'manipulates_state' : False
101
103
}
102
104
103
- def __init__ (self ):
105
+ def __init__ (self ) -> None :
104
106
super ().__init__ ()
105
- self .cycle = None
107
+ self .cycle = None # type: Tuple[Action]
106
108
107
- def strategy (self , opponent ) :
109
+ def strategy (self , opponent : Player ) -> Action :
108
110
if self .cycle :
109
111
return D
110
112
cycle = detect_cycle (opponent .history , min_size = 3 )
@@ -124,7 +126,7 @@ class EventualCycleHunter(CycleHunter):
124
126
125
127
name = 'Eventual Cycle Hunter'
126
128
127
- def strategy (self , opponent ) :
129
+ def strategy (self , opponent : Player ) -> None :
128
130
if len (opponent .history ) < 10 :
129
131
return C
130
132
if len (opponent .history ) == opponent .cooperations :
@@ -153,7 +155,7 @@ class MathConstantHunter(Player):
153
155
'manipulates_state' : False
154
156
}
155
157
156
- def strategy (self , opponent ) :
158
+ def strategy (self , opponent : Player ) -> Action :
157
159
"""
158
160
Check whether the number of cooperations in the first and second halves
159
161
of the history are close. The variance of the uniform distribution (1/4)
@@ -191,12 +193,12 @@ class RandomHunter(Player):
191
193
'manipulates_state' : False
192
194
}
193
195
194
- def __init__ (self ):
196
+ def __init__ (self ) -> None :
195
197
self .countCC = 0
196
198
self .countDD = 0
197
199
super ().__init__ ()
198
200
199
- def strategy (self , opponent ) :
201
+ def strategy (self , opponent : Player ) -> Action :
200
202
"""
201
203
A random player is unpredictable, which means the conditional frequency
202
204
of cooperation after cooperation, and defection after defections, should
0 commit comments