1- from axelrod .actions import Actions
1+ from axelrod .actions import Actions , Action
22from axelrod .player import Player
33from axelrod ._strategy_utils import detect_cycle
44
5+ from typing import List , Tuple
6+
57C , D = Actions .C , Actions .D
68
79
@@ -19,7 +21,7 @@ class DefectorHunter(Player):
1921 'manipulates_state' : False
2022 }
2123
22- def strategy (self , opponent ) :
24+ def strategy (self , opponent : Player ) -> Action :
2325 if len (self .history ) >= 4 and len (opponent .history ) == opponent .defections :
2426 return D
2527 return C
@@ -39,13 +41,13 @@ class CooperatorHunter(Player):
3941 'manipulates_state' : False
4042 }
4143
42- def strategy (self , opponent ) :
44+ def strategy (self , opponent : Player ) -> Action :
4345 if len (self .history ) >= 4 and len (opponent .history ) == opponent .cooperations :
4446 return D
4547 return C
4648
4749
48- def is_alternator (history ) :
50+ def is_alternator (history : List [ Action ]) -> bool :
4951 for i in range (len (history ) - 1 ):
5052 if history [i ] == history [i + 1 ]:
5153 return False
@@ -66,11 +68,11 @@ class AlternatorHunter(Player):
6668 'manipulates_state' : False
6769 }
6870
69- def __init__ (self ):
71+ def __init__ (self ) -> None :
7072 super ().__init__ ()
7173 self .is_alt = False
7274
73- def strategy (self , opponent ) :
75+ def strategy (self , opponent : Player ) -> Action :
7476 if len (opponent .history ) < 6 :
7577 return C
7678 if len (self .history ) == 6 :
@@ -100,11 +102,11 @@ class CycleHunter(Player):
100102 'manipulates_state' : False
101103 }
102104
103- def __init__ (self ):
105+ def __init__ (self ) -> None :
104106 super ().__init__ ()
105- self .cycle = None
107+ self .cycle = None # type: Tuple[Action]
106108
107- def strategy (self , opponent ) :
109+ def strategy (self , opponent : Player ) -> Action :
108110 if self .cycle :
109111 return D
110112 cycle = detect_cycle (opponent .history , min_size = 3 )
@@ -124,7 +126,7 @@ class EventualCycleHunter(CycleHunter):
124126
125127 name = 'Eventual Cycle Hunter'
126128
127- def strategy (self , opponent ) :
129+ def strategy (self , opponent : Player ) -> None :
128130 if len (opponent .history ) < 10 :
129131 return C
130132 if len (opponent .history ) == opponent .cooperations :
@@ -153,7 +155,7 @@ class MathConstantHunter(Player):
153155 'manipulates_state' : False
154156 }
155157
156- def strategy (self , opponent ) :
158+ def strategy (self , opponent : Player ) -> Action :
157159 """
158160 Check whether the number of cooperations in the first and second halves
159161 of the history are close. The variance of the uniform distribution (1/4)
@@ -191,12 +193,12 @@ class RandomHunter(Player):
191193 'manipulates_state' : False
192194 }
193195
194- def __init__ (self ):
196+ def __init__ (self ) -> None :
195197 self .countCC = 0
196198 self .countDD = 0
197199 super ().__init__ ()
198200
199- def strategy (self , opponent ) :
201+ def strategy (self , opponent : Player ) -> Action :
200202 """
201203 A random player is unpredictable, which means the conditional frequency
202204 of cooperation after cooperation, and defection after defections, should
0 commit comments