Skip to content

Commit 90c529b

Browse files
committed
Fixed formatting issues mentioned in PR
1 parent c20a106 commit 90c529b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

axelrod/strategies/axelrod_second.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,9 @@ def strategy(self, opponent: Player) -> Action:
755755
turn = len(self.history) + 1
756756
if turn == 1: return C
757757

758-
did_d = np.vectorize(lambda action: float(action == D))
759-
number_defects = np.sum(did_d(opponent.history))
760-
perc_defects = number_defects / turn # Size of numerator is smaller than denomator -- How it was in the Fortran.
758+
number_defects = opponent.defections
759+
# Size of numerator is smaller than denomator -- How it was in the Fortran.
760+
perc_defects = number_defects / turn
761761

762762
# If overly defect or appears random
763763
if turn > 39 and perc_defects > 0.39: return D
@@ -774,12 +774,12 @@ def strategy(self, opponent: Player) -> Action:
774774

775775
class WmAdams(Player):
776776
"""
777-
Strategy submitted to Axelrod's second tournament by William Adams (K49R),
777+
Strategy submitted to Axelrod's second tournament by William Adams (K44R),
778778
and came in fifth in that tournament.
779779
780-
Count the number of opponent defects after their first move, call
780+
Count the number of opponent defections after their first move, call
781781
`c_defect`. Defect if c_defect equals 4, 7, or 9. If c_defect > 9,
782-
then defect immediately after opponent defect with probability =
782+
then defect immediately after opponent defects with probability =
783783
(0.5)^(c_defect-1). Otherwise cooperate.
784784
785785
Names:
@@ -799,12 +799,11 @@ class WmAdams(Player):
799799
}
800800

801801
def strategy(self, opponent: Player) -> Action:
802-
if len(self.history) <=1:
802+
if len(self.history) <= 1:
803803
return C
804-
did_d = np.vectorize(lambda action: float(action == D))
805-
number_defects = np.sum(did_d(opponent.history[1:]))
804+
number_defects = opponent.defections
806805

807-
if number_defects == 4 or number_defects == 7 or number_defects == 9: return D
806+
if number_defects in [4, 7, 9]: return D
808807
if number_defects > 9 and opponent.history[-1] == D:
809-
return random_choice((0.5)**(number_defects-9))
808+
return random_choice((0.5) ** (number_defects - 9))
810809
return C

axelrod/tests/strategies/test_axelrod_second.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,19 @@ def test_strategy(self):
563563
actions = [(C, D)] * 4 + [(C, C)] * 100
564564
self.versus_test(defect_four, expected_actions=actions)
565565

566-
actions = [(C, D), (C, D), (C, D), (C, D), (C, D), (D, D), (C, D), (C, D), (D, D), (C, D), (D, D), (C, D), (D, D), (D, D), (D, D), (D, D)]
566+
actions = [(C, D), (C, D), (C, D), (C, D), (C, D), (D, D), (C, D),
567+
(C, D), (D, D), (C, D), (D, D), (C, D), (D, D), (D, D),
568+
(D, D), (D, D)]
567569
self.versus_test(axelrod.Defector(), expected_actions=actions, seed=1)
568-
actions = [(C, D), (C, D), (C, D), (C, D), (C, D), (D, D), (C, D), (C, D), (D, D), (C, D), (D, D), (D, D), (D, D), (C, D), (D, D), (D, D)]
570+
actions = [(C, D), (C, D), (C, D), (C, D), (C, D), (D, D), (C, D),
571+
(C, D), (D, D), (C, D), (D, D), (D, D), (D, D), (C, D),
572+
(D, D), (D, D)]
569573
self.versus_test(axelrod.Defector(), expected_actions=actions, seed=2)
570574

571575
# After responding to the 11th D (counted as 10 D), just start cooperating
572576
opponent_actions = [D] * 11 + [C] * 100
573577
changed_man = axelrod.MockPlayer(actions=opponent_actions)
574-
actions = [(C, D), (C, D), (C, D), (C, D), (C, D), (D, D), (C, D), (C, D), (D, D), (C, D), (D, D), (C, C)]
578+
actions = [(C, D), (C, D), (C, D), (C, D), (C, D), (D, D), (C, D),
579+
(C, D), (D, D), (C, D), (D, D), (C, C)]
575580
actions += [(C,C)] * 99
576581
self.versus_test(changed_man, expected_actions=actions, seed=1)

0 commit comments

Comments
 (0)