<s> from axelrod import Actions , Player <EOL> from axelrod . _strategy_utils import detect_cycle <EOL> C , D = Actions . C , Actions . D <EOL> class DefectorHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def strategy ( self , opponent ) : <EOL> if len ( self . history ) >= <NUM_LIT:4> and len ( opponent . history ) == opponent . defections : <EOL> return D <EOL> return C <EOL> class CooperatorHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def strategy ( self , opponent ) : <EOL> if len ( self . history ) >= <NUM_LIT:4> and len ( opponent . history ) == opponent . cooperations : <EOL> return D <EOL> return C <EOL> class AlternatorHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def strategy ( self , opponent ) : <EOL> oh = opponent . history <EOL> if len ( self . history ) >= <NUM_LIT:6> and all ( [ oh [ i ] != oh [ i + <NUM_LIT:1> ] for i in range ( len ( oh ) - <NUM_LIT:1> ) ] ) : <EOL> return D <EOL> return C <EOL> class CycleHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> @ staticmethod <EOL> def strategy ( opponent ) : <EOL> cycle = detect_cycle ( opponent . history , min_size = <NUM_LIT:2> ) <EOL> if cycle : <EOL> if len ( set ( cycle ) ) > <NUM_LIT:1> : <EOL> return D <EOL> return C <EOL> class EventualCycleHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> @ staticmethod <EOL> def strategy ( opponent ) : <EOL> if len ( opponent . history ) < <NUM_LIT:10> : <EOL> return C <EOL> if len ( opponent . history ) == opponent . cooperations : <EOL> return C <EOL> if detect_cycle ( opponent . history , offset = <NUM_LIT:15> ) : <EOL> return D <EOL> else : <EOL> return C <EOL> class MathConstantHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def strategy ( self , opponent ) : <EOL> """<STR_LIT>""" <EOL> n = len ( self . history ) <EOL> if n >= <NUM_LIT:8> and opponent . cooperations and opponent . defections : <EOL> start1 , end1 = <NUM_LIT:0> , n // <NUM_LIT:2> <EOL> start2 , end2 = n // <NUM_LIT:4> , <NUM_LIT:3> * n // <NUM_LIT:4> <EOL> start3 , end3 = n // <NUM_LIT:2> , n <EOL> count1 = opponent . history [ start1 : end1 ] . count ( C ) + self . history [ start1 : end1 ] . count ( C ) <EOL> count2 = opponent . history [ start2 : end2 ] . count ( C ) + self . history [ start2 : end2 ] . count ( C ) <EOL> count3 = opponent . history [ start3 : end3 ] . count ( C ) + self . history [ start3 : end3 ] . count ( C ) <EOL> ratio1 = <NUM_LIT:0.5> * count1 / ( end1 - start1 ) <EOL> ratio2 = <NUM_LIT:0.5> * count2 / ( end2 - start2 ) <EOL> ratio3 = <NUM_LIT:0.5> * count3 / ( end3 - start3 ) <EOL> if abs ( ratio1 - ratio2 ) < <NUM_LIT> and abs ( ratio1 - ratio3 ) < <NUM_LIT> : <EOL> return D <EOL> return C <EOL> class RandomHunter ( Player ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def __init__ ( self ) : <EOL> self . countCC = <NUM_LIT:0> <EOL> self . countDD = <NUM_LIT:0> <EOL> Player . __init__ ( self ) <EOL> def strategy ( self , opponent ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . history ) > <NUM_LIT:1> : <EOL> if self . history [ - <NUM_LIT:2> ] == C and opponent . history [ - <NUM_LIT:1> ] == C : <EOL> self . countCC += <NUM_LIT:1> <EOL> if self . history [ - <NUM_LIT:2> ] == D and opponent . history [ - <NUM_LIT:1> ] == D : <EOL> self . countDD += <NUM_LIT:1> <EOL> n = len ( self . history ) <EOL> if n > <NUM_LIT:10> : <EOL> probabilities = [ ] <EOL> if self . cooperations > <NUM_LIT:5> : <EOL> probabilities . append ( <NUM_LIT:1.0> * self . countCC / self . cooperations ) <EOL> if self . defections > <NUM_LIT:5> : <EOL> probabilities . append ( <NUM_LIT:1.0> * self . countDD / self . defections ) <EOL> if probabilities and all ( [ abs ( p - <NUM_LIT:0.5> ) < <NUM_LIT> for p in probabilities ] ) : <EOL> return D <EOL> return C <EOL> def reset ( self ) : <EOL> self . countCC = <NUM_LIT:0> <EOL> self . countDD = <NUM_LIT:0> <EOL> Player . reset ( self ) </s>
