<s> from collections import defaultdict <EOL> from axelrod import Actions , Player , init_args <EOL> C , D = Actions . C , Actions . D <EOL> class Retaliate ( Player ) : <EOL> """<STR_LIT>""" <EOL> classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : set ( ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> @ init_args <EOL> def __init__ ( self , retaliation_threshold = <NUM_LIT:0.1> ) : <EOL> """<STR_LIT>""" <EOL> Player . __init__ ( self ) <EOL> self . retaliation_threshold = retaliation_threshold <EOL> self . name = ( <EOL> '<STR_LIT>' + <EOL> str ( self . retaliation_threshold ) + '<STR_LIT:)>' ) <EOL> self . play_counts = defaultdict ( int ) <EOL> def strategy ( self , opponent ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . history ) : <EOL> last_round = ( self . history [ - <NUM_LIT:1> ] , opponent . history [ - <NUM_LIT:1> ] ) <EOL> self . play_counts [ last_round ] += <NUM_LIT:1> <EOL> CD_count = self . play_counts [ ( C , D ) ] <EOL> DC_count = self . play_counts [ ( D , C ) ] <EOL> if CD_count > DC_count * self . retaliation_threshold : <EOL> return D <EOL> return C <EOL> def reset ( self ) : <EOL> Player . reset ( self ) <EOL> self . play_counts = defaultdict ( int ) <EOL> class Retaliate2 ( Retaliate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , retaliation_threshold = <NUM_LIT> ) : <EOL> super ( Retaliate2 , self ) . __init__ ( <EOL> retaliation_threshold = retaliation_threshold ) <EOL> class Retaliate3 ( Retaliate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , retaliation_threshold = <NUM_LIT> ) : <EOL> super ( Retaliate3 , self ) . __init__ ( <EOL> retaliation_threshold = retaliation_threshold ) <EOL> class LimitedRetaliate ( Player ) : <EOL> """<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> @ init_args <EOL> def __init__ ( self , retaliation_threshold = <NUM_LIT:0.1> , retaliation_limit = <NUM_LIT:20> ) : <EOL> """<STR_LIT>""" <EOL> Player . __init__ ( self ) <EOL> self . retaliating = False <EOL> self . retaliation_count = <NUM_LIT:0> <EOL> self . retaliation_threshold = retaliation_threshold <EOL> self . retaliation_limit = retaliation_limit <EOL> self . play_counts = defaultdict ( int ) <EOL> self . init_args = ( retaliation_threshold , retaliation_limit ) <EOL> self . name = ( <EOL> '<STR_LIT>' + <EOL> str ( self . retaliation_threshold ) + <EOL> '<STR_LIT:/>' + str ( self . retaliation_limit ) + '<STR_LIT:)>' ) <EOL> def strategy ( self , opponent ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . history ) : <EOL> last_round = ( self . history [ - <NUM_LIT:1> ] , opponent . history [ - <NUM_LIT:1> ] ) <EOL> self . play_counts [ last_round ] += <NUM_LIT:1> <EOL> CD_count = self . play_counts [ ( C , D ) ] <EOL> DC_count = self . play_counts [ ( D , C ) ] <EOL> if CD_count > DC_count * self . retaliation_threshold : <EOL> self . retaliating = True <EOL> else : <EOL> self . retaliating = False <EOL> self . retaliation_count = <NUM_LIT:0> <EOL> if self . retaliating : <EOL> if self . retaliation_count < self . retaliation_limit : <EOL> self . retaliation_count += <NUM_LIT:1> <EOL> return D <EOL> else : <EOL> self . retaliation_count = <NUM_LIT:0> <EOL> self . retaliating = False <EOL> return C <EOL> def reset ( self ) : <EOL> Player . reset ( self ) <EOL> self . play_counts = defaultdict ( int ) <EOL> self . retaliating = False <EOL> self . retaliation_count = <NUM_LIT:0> <EOL> class LimitedRetaliate2 ( LimitedRetaliate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , retaliation_threshold = <NUM_LIT> , retaliation_limit = <NUM_LIT:15> ) : <EOL> super ( LimitedRetaliate2 , self ) . __init__ ( <EOL> retaliation_threshold = retaliation_threshold , <EOL> retaliation_limit = retaliation_limit ) <EOL> class LimitedRetaliate3 ( LimitedRetaliate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , retaliation_threshold = <NUM_LIT> , retaliation_limit = <NUM_LIT:20> ) : <EOL> super ( LimitedRetaliate3 , self ) . __init__ ( <EOL> retaliation_threshold = retaliation_threshold , <EOL> retaliation_limit = retaliation_limit ) </s>
