@@ -492,15 +492,18 @@ def strategy(opponent: Player) -> Action:
492492
493493@FinalTransformer ((D , D ), name_prefix = None )
494494class SteinAndRapoport (Player ):
495- """
496- A player who plays according to statistic methods.
497- Begins by playing C for the first four (4) rounds , then it plays
498- tit for tat and at the last 2 round it Defects. Every 15 turns it
499- run a chi-squared test to check whether the opponent behaves randomly
500- or not . In case the opponent behaves randomly then Stein_and_Rapoport
501- Defects untill the next 15 round (where we check again), otherwise he
502- still plays TitForTat.
503- """
495+ """
496+ A player who plays according to statistic methods.
497+ Begins by playing C for the first four (4) rounds , then it plays
498+ tit for tat and at the last 2 round it Defects. Every 15 turns it
499+ run a chi-squared test to check whether the opponent behaves randomly
500+ or not . In case the opponent behaves randomly then Stein_and_Rapoport
501+ Defects untill the next 15 round (where we check again), otherwise he
502+ still plays TitForTat.
503+
504+ Names:
505+ - SteinAndRapoport [Axelrod1980]_
506+ """
504507
505508 name = 'Stein and Rapoport'
506509 classifier = {
@@ -527,31 +530,30 @@ def __init__(self, alpha: float=0.05) -> None:
527530 self .alpha = 0.05
528531
529532 def strategy (self , opponent : Player , chi_tests = [0 ]) -> Action :
530- # chi-tests == 0 then we play TitForTat
531533 round_number = len (self .history ) + 1
532534
533535 # First 4 moves
534- if round_number < 5 :
536+ if round_number < 5 :
535537 return C
536538
537539 # For first 15 rounds tit for tat as we dont know opponents strategy
538- if round_number < 16 :
539- if opponent .history [- 1 ] == 'D' :
540+ if round_number < 16 :
541+ if opponent .history [- 1 ] == 'D' :
540542 return D
541543 else :
542544 return C
543545
544- if len (self .history ) % 15 == 0 :
545- if chisquare ([opponent .cooperations , opponent .defections ]).pvalue >= self .alpha :
546+ if len (self .history ) % 15 == 0 :
547+ if chisquare ([opponent .cooperations , opponent .defections ]).pvalue >= self .alpha :
546548 chi_tests .append (1 )
547- else :
549+ else :
548550 chi_tests .append (0 )
549551
550- if chi_tests [- 1 ] == 1 :
552+ if chi_tests [- 1 ] == 1 :
551553 # Defect if opponent plays randomly
552554 return D
553555 else : # TitForTatat if opponent plays not randomly
554- if opponent .history [- 1 ] == 'D' :
556+ if opponent .history [- 1 ] == 'D' :
555557 return D
556- else :
558+ else :
557559 return C
0 commit comments