@@ -391,37 +391,76 @@ def test_strategy(self):
391391
392392class SteinAndRapoport (TestPlayer ):
393393
394- name = "SteinAndRapoport "
394+ name = "Stein and Rapoport: 0.05: ('D', 'D') "
395395 player = axelrod .SteinAndRapoport
396396 expected_classifier = {
397397 'memory_depth' : 15 ,
398398 'long_run_time' : False ,
399399 'stochastic' : False ,
400- 'makes_use_of' : set () ,
400+ 'makes_use_of' : { 'length' } ,
401401 'inspects_source' : False ,
402402 'manipulates_source' : False ,
403403 'manipulates_state' : False
404404 }
405405
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+
406415 def test_strategy (self ):
407416 self .first_play_test (C )
408417
409418 # Our Player (SteinAndRapoport) vs Cooperator
410419 # After 15th round (pvalue < alpha) still plays titfortat
420+ # Note it always defects on the last two rounds
411421 opponent = axelrod .Cooperator ()
412422 actions = [(C , C )] * 17 + [(D , C )] * 2
413- self .versus_test (opponent , expected_actions = actions )
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 })
414430
415431 # Our Player (SteinAndRapoport) vs Defector
416432 # After 15th round (pvalue < alpha) still plays titfortat
417- opponent = axelrod .Cooperator ()
433+ opponent = axelrod .Defector ()
418434 actions = [(C , D )] * 4 + [(D , D )] * 15
419- self .versus_test (opponent , expected_actions = actions )
435+ self .versus_test (opponent , expected_actions = actions ,
436+ attrs = {"opponent_is_random" : False })
420437
421438 # Our Player (SteinAndRapoport) vs Alternator
422439 # After 15th round (pvalue > alpha) starts defect
423440 opponent = axelrod .Alternator ()
424- actions = [(C , C ), (C , D ), (C , C ), (C , D ), (D , C ), (C , D ), (D , C ),
425- (C , D ), (D , C ), (C , D ), (D , C ), (C , D ),(D , C ), (C , D ),
426- (D , C ), (D , D ), (D , C ), (D , D ), (D , C )]
427- self .versus_test (opponent , expected_actions = actions )
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