@@ -387,3 +387,80 @@ def test_strategy(self):
387387 actions = [(C , C ), (C , C ), (D , C ), (C , C ), (C , C ), (D , C )]
388388 self .versus_test (axelrod .Cooperator (), expected_actions = actions ,
389389 seed = 10 )
390+
391+
392+ class SteinAndRapoport (TestPlayer ):
393+
394+ name = "Stein and Rapoport: 0.05: ('D', 'D')"
395+ player = axelrod .SteinAndRapoport
396+ expected_classifier = {
397+ 'memory_depth' : 15 ,
398+ 'long_run_time' : False ,
399+ 'stochastic' : False ,
400+ 'makes_use_of' : {'length' },
401+ 'inspects_source' : False ,
402+ 'manipulates_source' : False ,
403+ 'manipulates_state' : False
404+ }
405+
406+ def test_init (self ):
407+ player = self .player ()
408+ self .assertEqual (player .alpha , 0.05 )
409+ self .assertIsNone (player .opponent_is_random )
410+
411+ player = self .player (alpha = .5 )
412+ self .assertEqual (player .alpha , 0.5 )
413+ self .assertIsNone (player .opponent_is_random )
414+
415+ def test_strategy (self ):
416+ self .first_play_test (C )
417+
418+ # Our Player (SteinAndRapoport) vs Cooperator
419+ # After 15th round (pvalue < alpha) still plays titfortat
420+ # Note it always defects on the last two rounds
421+ opponent = axelrod .Cooperator ()
422+ actions = [(C , C )] * 17 + [(D , C )] * 2
423+ self .versus_test (opponent , expected_actions = actions ,
424+ attrs = {"opponent_is_random" : False })
425+
426+ actions = actions [:- 2 ] + [(C , C )] * 2
427+ self .versus_test (opponent , expected_actions = actions [:- 2 ],
428+ match_attributes = {"length" : - 1 },
429+ attrs = {"opponent_is_random" : False })
430+
431+ # Our Player (SteinAndRapoport) vs Defector
432+ # After 15th round (pvalue < alpha) still plays titfortat
433+ opponent = axelrod .Defector ()
434+ actions = [(C , D )] * 4 + [(D , D )] * 15
435+ self .versus_test (opponent , expected_actions = actions ,
436+ attrs = {"opponent_is_random" : False })
437+
438+ # Our Player (SteinAndRapoport) vs Alternator
439+ # After 15th round (pvalue > alpha) starts defect
440+ opponent = axelrod .Alternator ()
441+ actions = [(C , C ), (C , D ), (C , C ), (C , D )]
442+
443+ # On 15th round carry out chisquare test
444+ actions += [(D , C ), (C , D )] * 5 + [(D , C )]
445+
446+ # Defect throughout
447+ actions += [(D , D ), (D , C ), (D , D ), (D , C )]
448+
449+ self .versus_test (opponent , expected_actions = actions ,
450+ attrs = {"opponent_is_random" : True })
451+
452+ # The test is carried out again every 15 rounds.
453+ # If the strategy alternates for the first 12 rounds and then cooperates
454+ # it is no longer recognised as random
455+ opponent = axelrod .MockPlayer ([C , D ] * 6 + [C ] * 50 )
456+
457+ actions = [(C , C ), (C , D ), (C , C ), (C , D )]
458+ # On 15th round carry out chisquare test
459+ actions += [(D , C ), (C , D )] * 4 + [(D , C ), (C , C ), (D , C )]
460+ # Defect throughout and carry out chisquare test on round 30
461+ # Opponent is no longer recognised as random, revert to TfT
462+ actions += [(D , C )] * 14 + [(C , C )]
463+ self .versus_test (opponent , expected_actions = actions ,
464+ match_attributes = {"length" : - 1 },
465+ attrs = {"opponent_is_random" : False })
466+
0 commit comments