@@ -130,3 +130,46 @@ def test_strategy(self):
130130 opponent = axelrod .MockPlayer ([C ] * 4 + [D ] + [C ] * 4 + [D ])
131131 actions = [(C , C )] * 4 + [(C , D )] + [(C , C )] * 4 + [(C , D ), (C , C )]
132132 self .versus_test (opponent = opponent , expected_actions = actions )
133+
134+
135+ class TestTrickyLevelPunisher (TestPlayer ):
136+
137+ name = "Level Punisher"
138+ player = axelrod .LevelPunisher
139+ expected_classifier = {
140+ 'memory_depth' : float ('inf' ), # Long memory
141+ 'stochastic' : False ,
142+ 'makes_use_of' : set (),
143+ 'long_run_time' : False ,
144+ 'inspects_source' : False ,
145+ 'manipulates_source' : False ,
146+ 'manipulates_state' : False
147+ }
148+
149+ def test_strategy (self ):
150+ # Cooperates if the turns played are less than 10.
151+ actions = [(C , C )] * 9
152+ self .versus_test (opponent = axelrod .Cooperator (),
153+ expected_actions = actions )
154+
155+ # After 10 rounds
156+ # Check if number of defections by opponent is greater than 20%
157+ opponent = axelrod .MockPlayer ([C ] * 4 + [D ] * 2 + [C ] * 3 + [D ])
158+ actions = [(C , C )] * 4 + [(C , D )] * 2 + [(C , C )] * 3 + [(C , D ), (D , C )]
159+ self .versus_test (opponent = opponent , expected_actions = actions )
160+
161+ # Check if number of defections by opponent is greater than 10%
162+ opponent = axelrod .MockPlayer ([C ] * 4 + [D ] + [C ] * 4 + [D ])
163+ actions = [(C , C )] * 4 + [(C , D )] + [(C , C )] * 4 + [(C , D ), (C , C )]
164+ self .versus_test (opponent = opponent , expected_actions = actions )
165+
166+ # After 10 rounds
167+ # Check if number of defections by opponent is greater than 5%
168+ opponent = axelrod .MockPlayer ([C ] * 4 + [D ] + [C ] * 5 )
169+ actions = [(C , C )] * 4 + [(C , D )] + [(C , C )] * 5
170+ self .versus_test (opponent = opponent , expected_actions = actions )
171+
172+ # Check if number of defections by opponent is less than 5%
173+ opponent = axelrod .MockPlayer ([C ]* 10 )
174+ actions = [(C , C )] * 5
175+ self .versus_test (opponent = opponent , expected_actions = actions )
0 commit comments