@@ -492,15 +492,18 @@ def strategy(opponent: Player) -> Action:
492
492
493
493
@FinalTransformer ((D , D ), name_prefix = None )
494
494
class 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
+ """
504
507
505
508
name = 'Stein and Rapoport'
506
509
classifier = {
@@ -527,31 +530,30 @@ def __init__(self, alpha: float=0.05) -> None:
527
530
self .alpha = 0.05
528
531
529
532
def strategy (self , opponent : Player , chi_tests = [0 ]) -> Action :
530
- # chi-tests == 0 then we play TitForTat
531
533
round_number = len (self .history ) + 1
532
534
533
535
# First 4 moves
534
- if round_number < 5 :
536
+ if round_number < 5 :
535
537
return C
536
538
537
539
# 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' :
540
542
return D
541
543
else :
542
544
return C
543
545
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 :
546
548
chi_tests .append (1 )
547
- else :
549
+ else :
548
550
chi_tests .append (0 )
549
551
550
- if chi_tests [- 1 ] == 1 :
552
+ if chi_tests [- 1 ] == 1 :
551
553
# Defect if opponent plays randomly
552
554
return D
553
555
else : # TitForTatat if opponent plays not randomly
554
- if opponent .history [- 1 ] == 'D' :
556
+ if opponent .history [- 1 ] == 'D' :
555
557
return D
556
- else :
558
+ else :
557
559
return C
0 commit comments