Skip to content

Commit

Permalink
Minor formatting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffney2010 committed Nov 25, 2017
1 parent 90c529b commit da80753
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ class WmAdams(Player):
Strategy submitted to Axelrod's second tournament by William Adams (K44R),
and came in fifth in that tournament.
Count the number of opponent defections after their first move, call
Count the number of opponent defections after their first move, call
`c_defect`. Defect if c_defect equals 4, 7, or 9. If c_defect > 9,
then defect immediately after opponent defects with probability =
then defect immediately after opponent defects with probability =
(0.5)^(c_defect-1). Otherwise cooperate.
Names:
Expand Down
56 changes: 31 additions & 25 deletions axelrod/tests/strategies/test_axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,15 @@ def test_strategy(self):

# Now we have to test the detect-random logic, which doesn't pick up
# until after 26 turns. So we need a big sample.
actions = [(C, D), (D, D), (D, D), (D, D), (D, D), (D, C), (C, C), (C, D),
(C, C), (D, D), (D, C), (C, C), (C, D), (D, D), (C, D), (D, D),
(D, C), (C, C), (D, C), (C, C), (C, D), (D, D), (D, C), (C, D),
(D, C), (C, C), (C, D),
actions = [(C, D), (D, D), (D, D), (D, D), (D, D), (D, C), (C, C),
(C, D), (C, C), (D, D), (D, C), (C, C), (C, D), (D, D),
(C, D), (D, D), (D, C), (C, C), (D, C), (C, C), (C, D),
(D, D), (D, C), (C, D), (D, C), (C, C), (C, D),
# Success detect random opponent for remaining turns.
(D, D),(D, D),(D, D),(D, C),(D, D),(D, C),(D, D),(D, C),(D, D),
(D, C),(D, C),(D, D),(D, D),(D, C),(D, C),(D, C),(D, C),(D, D),
(D, C),(D, C),(D, C),(D, C),(D, D)]
(D, D), (D, D), (D, D), (D, C), (D, D), (D, C), (D, D),
(D, C), (D, D), (D, C), (D, C), (D, D), (D, D), (D, C),
(D, C), (D, C), (D, C), (D, D), (D, C), (D, C), (D, C),
(D, C), (D, D)]
self.versus_test(axelrod.Random(0.5), expected_actions=actions, seed=10)

class TestBorufsen(TestPlayer):
Expand All @@ -475,16 +476,21 @@ def test_strategy(self):
self.versus_test(axelrod.Defector(), expected_actions=actions)

# Alternates with additional coop, every sixth turn
# Won't be labeled as random, since 2/3 of opponent's C follow player's C
# `flip_next_defect` will get set on the sixth turn, which changes the seventh action
# Won't be labeled as random, since 2/3 of opponent's C follow
# player's C
# `flip_next_defect` will get set on the sixth turn, which changes the
# seventh action
# Note that the first two turns of each period of six aren't
# marked as echoes, and the third isn't marked that way until the fourth turn.
# marked as echoes, and the third isn't marked that way until the
# fourth turn.
actions = [(C, C), (C, D), (D, C), (C, D), (D, C), (C, D)] * 20
self.versus_test(axelrod.Alternator(), expected_actions=actions)

# Basically does tit-for-tat against Win-Shift, Lose-Stay D
# After 26 turns, will detect random since half of opponent's C follow Cs
# Coming out of it, there will be new pattern. Then random is detected again.
# After 26 turns, will detect random since half of opponent's C follow
# Cs
# Coming out of it, there will be new pattern. Then random is detected
# again.
actions = [(C, D), (D, C), (C, C)] * 8 + \
[(C, D), (D, C)] + [(D, C)] * 25 + \
[(D, C)] + [(C, C), (C, D), (D, C)] * 8 + \
Expand All @@ -505,7 +511,7 @@ class TestCave(TestPlayer):
}

def test_strategy(self):
actions = [(C, C)] * 100
actions = [(C, C)] * 100
self.versus_test(axelrod.Cooperator(), expected_actions=actions)

# It will take until turn 18 to respond decide to repond D->D
Expand All @@ -531,16 +537,16 @@ def test_strategy(self):

#Here it will take until turn 40 to detect random and defect
actions = [(C, C)]
actions += [(C, D), (D, C), (C, D), (D, C), (C, D), (C, C), (C, D),
(C, C), (C, D), (D, C), (C, D), (D, C), (C, D), (D, C),
(C, D), (C, C), (C, D), (D, C), (C, D), (D, C), (C, D),
(D, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C),
(C, D), (D, C), (C, D), (D, C), (C, D), (D, C), (C, D)] #Randomly choose
actions += [(C, D), (D, C), (C, D), (D, C), (C, D), (C, C), (C, D),
(C, C), (C, D), (D, C), (C, D), (D, C), (C, D), (D, C),
(C, D), (C, C), (C, D), (D, C), (C, D), (D, C), (C, D),
(D, C), (C, D), (C, C), (C, D), (C, C), (C, D), (C, C),
(C, D), (D, C), (C, D), (D, C), (C, D), (D, C), (C, D)] #Randomly choose
actions += [(D, C), (C, D), (D, C)] # 17 D have come, so tit for tat for a while
actions += [(D, D), (D, C)] * 100 # Random finally detected
self.versus_test(axelrod.Alternator(), expected_actions=actions, seed=2)

class TestCave(TestPlayer):
class TestWmAdams(TestPlayer):
name = "WmAdams"
player = axelrod.WmAdams
expected_classifier = {
Expand All @@ -564,18 +570,18 @@ def test_strategy(self):
self.versus_test(defect_four, expected_actions=actions)

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)]
(C, D), (D, D), (C, D), (D, D), (C, D), (D, D), (D, D),
(D, D), (D, D)]
self.versus_test(axelrod.Defector(), expected_actions=actions, seed=1)
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)]
(C, D), (D, D), (C, D), (D, D), (D, D), (D, D), (C, D),
(D, D), (D, D)]
self.versus_test(axelrod.Defector(), expected_actions=actions, seed=2)

# After responding to the 11th D (counted as 10 D), just start cooperating
opponent_actions = [D] * 11 + [C] * 100
changed_man = axelrod.MockPlayer(actions=opponent_actions)
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)]
actions += [(C,C)] * 99
(C, D), (D, D), (C, D), (D, D), (C, C)]
actions += [(C, C)] * 99
self.versus_test(changed_man, expected_actions=actions, seed=1)

0 comments on commit da80753

Please sign in to comment.