Skip to content

Commit 100e511

Browse files
committed
New changes
1 parent 204d498 commit 100e511

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

axelrod/strategies/_strategies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .averagecopier import AverageCopier, NiceAverageCopier
77
from .axelrod_first import (
88
Davis, RevisedDowning, Feld, Grofman, Nydegger, Joss, Shubik, Tullock,
9-
UnnamedStrategy)
9+
UnnamedStrategy, SteinAndRapoport)
1010
from .axelrod_second import Champion, Eatherley, Tester
1111
from .backstabber import BackStabber, DoubleCrosser
1212
from .better_and_better import BetterAndBetter
@@ -72,7 +72,6 @@
7272
from .selfsteem import SelfSteem
7373
from .shortmem import ShortMem
7474
from .stalker import Stalker
75-
from .axelrod_first import SteinAndRapoport
7675
from .titfortat import (
7776
TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat,
7877
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats,

axelrod/strategies/axelrod_first.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,18 @@ def strategy(opponent: Player) -> Action:
492492

493493
@FinalTransformer((D, D), name_prefix=None)
494494
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+
"""
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

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ matplotlib>=1.4.2
33
hypothesis>=3.2
44
tqdm>=3.4.0
55
prompt-toolkit>=1.0.7
6+
scipy>=0.19.0

0 commit comments

Comments
 (0)