@@ -244,7 +244,7 @@ def test_strategy(self):
244
244
self .versus_test (opponent , expected_actions = actions )
245
245
246
246
247
- class TestGeneralSoftGrudger (TestSoftGrudger ):
247
+ class TestGeneralSoftGrudger (TestPlayer ):
248
248
249
249
name = "General Soft Grudger: n=1,d=4,c=2"
250
250
player = axl .GeneralSoftGrudger
@@ -259,52 +259,30 @@ class TestGeneralSoftGrudger(TestSoftGrudger):
259
259
}
260
260
261
261
def test_strategy (self ):
262
- # the default follows SoftGrudger
263
- super (TestGeneralSoftGrudger , self ).test_strategy ()
264
-
265
- def test_set_n (self ):
266
- # grudge response only activates if opponent's last 'n' plays were D
267
- init_kwargs = {'n' : 3 }
268
- grudge_response_d = [(D , D )] * 4 + [(C , D )] * 2
269
- grudge_response_c = [(D , C )] * 4 + [(C , C )] * 2
270
-
271
- opponent = axl .Defector ()
272
- actions = [(C , D )] * 3 + grudge_response_d * 5
273
- self .versus_test (opponent , expected_actions = actions ,
274
- init_kwargs = init_kwargs )
275
-
276
- two_defections = [C , D , D ]
277
- opponent = axl .MockPlayer (actions = two_defections )
278
- actions = [(C , C ), (C , D ), (C , D )] * 5
279
- self .versus_test (opponent , expected_actions = actions ,
280
- init_kwargs = init_kwargs )
281
-
282
- three_defections = [C ] * 10 + [D , D , D ]
283
- opponent = axl .MockPlayer (actions = three_defections )
284
- actions_start = [(C , C )] * 10 + [(C , D )] * 3
285
- subsequent = grudge_response_c + [(C , C )] * 4 + [(C , D )] * 3
286
- actions = actions_start + subsequent * 5
287
- self .versus_test (opponent , expected_actions = actions ,
288
- init_kwargs = init_kwargs )
289
-
290
- def test_set_d_and_c (self ):
291
- # Sets the number of D's then C's in the grudge response.
292
- init_kwargs = {'d' : 3 , 'c' : 3 }
293
- grudge_response_d = [(D , D )] * 3 + [(C , D )] * 3
294
- grudge_response_c = [(D , C )] * 3 + [(C , C )] * 3
295
-
296
- opponent = axl .Defector ()
297
- actions = [(C , D )] + grudge_response_d * 5
298
- self .versus_test (opponent , expected_actions = actions ,
299
- init_kwargs = init_kwargs )
300
-
301
- opponent_actions = [C ] * 10 + [D ]
302
- opponent = axl .MockPlayer (actions = opponent_actions )
303
- actions_start = [(C , C )] * 10 + [(C , D )]
304
- subsequent = grudge_response_c + [(C , C )] * 4 + [(C , D )]
305
- actions = actions_start + subsequent * 5
306
- self .versus_test (opponent , expected_actions = actions ,
307
- init_kwargs = init_kwargs )
262
+ """Test strategy with multiple initial parameters"""
263
+
264
+ # Starts by cooperating.
265
+ self .first_play_test (C )
266
+
267
+ # Testing default parameters of n=1, d=4, c=2 (same as Soft Grudger)
268
+ actions = [(C , D ), (D , D ), (D , C ), (D , C ), (D , D ), (C , D ),
269
+ (C , C ), (C , C )]
270
+ self .versus_test (axl .MockPlayer (actions = [D , D , C , C ]),
271
+ expected_actions = actions )
272
+
273
+ # Testing n=2, d=4, c=2
274
+ actions = [(C , D ), (C , D ), (D , C ), (D , C ), (D , D ), (D , D ),
275
+ (C , C ), (C , C )]
276
+ self .versus_test (axl .MockPlayer (actions = [D , D , C , C ]),
277
+ expected_actions = actions ,
278
+ init_kwargs = {"n" : 2 })
279
+
280
+ # Testing n=1, d=1, c=1
281
+ actions = [(C , D ), (D , D ), (C , C ), (C , C ), (C , D ), (D , D ),
282
+ (C , C ), (C , C )]
283
+ self .versus_test (axl .MockPlayer (actions = [D , D , C , C ]),
284
+ expected_actions = actions ,
285
+ init_kwargs = {"n" : 1 , "d" : 1 , "c" : 1 })
308
286
309
287
def test_edge_case_n_is_zero (self ):
310
288
# Always uses grudge response.
0 commit comments