Skip to content

Commit

Permalink
added game test. fixed docstring issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-s-s authored and drvinceknight committed Aug 3, 2017
1 parent 68c357e commit 01c31c9
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion axelrod/strategies/axelrod_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def strategy(self, opponent: Player) -> Action:
self.opponent_is_random = p_value >= self.alpha

if self.opponent_is_random:
# MyCooperator if opponent plays randomly
# Defect if opponent plays randomly
return D
else: # TitForTat if opponent plays not randomly
return opponent.history[-1]
Expand Down
2 changes: 1 addition & 1 deletion axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self) -> None:
self.is_TFT = False

def strategy(self, opponent: Player) -> Action:
# MyCooperator on the first move
# Defect on the first move
if not opponent.history:
return D
# Am I TFT?
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/cooperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class TrickyCooperator(Player):
def strategy(self, opponent: Player) -> Action:
"""Almost always cooperates, but will try to trick the opponent by defecting.
MyCooperator once in a while in order to get a better payout.
After 3 rounds, if opponent has not defected to a max history depth of 10, MyCooperator.
Defect once in a while in order to get a better payout.
After 3 rounds, if opponent has not defected to a max history depth of 10, Defect.
"""
if (self._has_played_enough_rounds_to_be_tricky() and
self._opponents_has_cooperated_enough_to_be_tricky(opponent)):
Expand Down
2 changes: 1 addition & 1 deletion axelrod/strategies/defector.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def strategy(self, opponent: Player) -> Action:
"""Almost always defects, but will try to trick the opponent into
cooperating.
MyCooperator if opponent has cooperated at least once in the past and has
Defect if opponent has cooperated at least once in the past and has
defected for the last 3 turns in a row.
"""
if C in opponent.history and opponent.history[-3:] == [D] * 3:
Expand Down
2 changes: 1 addition & 1 deletion axelrod/strategies/gobymajority.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(self) -> None:
class HardGoByMajority(GoByMajority):
"""A player examines the history of the opponent: if the opponent has more
defections than cooperations then the player defects. In case of equal
number of defections and cooperations this player will MyCooperator.
number of defections and cooperations this player will Defect.
An optional memory attribute will limit the number of turns remembered (by
default this is 0)
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def strategy(self, opponent: Player) -> Action:
if self.history[-1] != opponent.history[-1]:
self.randomness_counter += 1
# Compare counts to thresholds
# If randomness_counter exceeds Y, MyCooperator for the remainder
# If randomness_counter exceeds Y, Defect for the remainder
if self.randomness_counter >= self.randomness_threshold:
move = D
else:
Expand Down Expand Up @@ -683,7 +683,7 @@ def strategy(self, opponent: Player) -> Action:
class EugineNier(Player):
"""
Plays similar to Tit-for-Tat, but with two conditions:
1) Always MyCooperator on Last Move
1) Always Defect on Last Move
2) If other player defects five times, switch to all defects.
Names:
Expand Down
4 changes: 2 additions & 2 deletions axelrod/tests/strategies/test_axelrod_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def test_strategy(self):
# On 15th round carry out chi-square test.
actions += [(D, C), (C, D)] * 5 + [(D, C)]

# MyCooperator throughout.
# Defect throughout.
actions += [(D, D), (D, C), (D, D), (D, C)]

self.versus_test(opponent, expected_actions=actions,
Expand All @@ -431,7 +431,7 @@ def test_strategy(self):
actions = [(C, C), (C, D), (C, C), (C, D)]
# On 15th round carry out chi-square test.
actions += [(D, C), (C, D)] * 4 + [(D, C), (C, C), (D, C)]
# MyCooperator throughout and carry out chi-square test on round 30.
# Defect throughout and carry out chi-square test on round 30.
# Opponent is no longer recognised as random, revert to TFT.
actions += [(D, C)] * 14 + [(C, C)]
self.versus_test(opponent, expected_actions=actions,
Expand Down
2 changes: 1 addition & 1 deletion axelrod/tests/strategies/test_dbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUp(self):
def test_minimaxTreeSearch_cooperator(self):
"""
Tests the minimax_tree_search function when playing against a
Cooperator player. Output == 0 means Cooperate, 1 means MyCooperator.
Cooperator player. Output == 0 means Cooperate, 1 means Defect.
The best (hence expected) answer to Cooperator is to defect
whatever the input position is.
"""
Expand Down
2 changes: 1 addition & 1 deletion axelrod/tests/strategies/test_retaliate.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_strategy(self):
attrs={"retaliation_count": 0},
init_kwargs={"retaliation_limit": 2})

# MyCooperator again after cooperating
# Defect again after cooperating
actions = [(C, C), (C, D), (D, C), (D, D), (C, C), (D, D), (D, C)]
self.versus_test(opponent=opponent, expected_actions=actions,
attrs={"retaliation_count": 2},
Expand Down
2 changes: 1 addition & 1 deletion axelrod/tests/strategies/test_shortmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_strategy(self):
actions = [(C, C)] * 11 + [(C, D)] * 4
self.versus_test(opponent=axelrod.MockPlayer(actions=[C] * 11 + [D] * 4), expected_actions=actions)

#MyCooperator if in the last ten moves, Defections - Cooperations >= 3
#Defect if in the last ten moves, Defections - Cooperations >= 3
actions = [(C, D)] * 11 + [(D, C)] * 4
self.versus_test(opponent=axelrod.MockPlayer(actions=[D] * 11 + [C] * 4), expected_actions=actions)

Expand Down
2 changes: 1 addition & 1 deletion axelrod/tests/strategies/test_worse_and_worse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_strategy(self):
self.versus_test(axelrod.Cooperator(), expected_actions = actions,
seed=8)

# 6 Rounds Cooperate and MyCooperator no matter oponent
# 6 Rounds Cooperate and Defect no matter oponent
actions = [(C, D)] * 6 + [(D, D)] + [(C, D)] * 3
self.versus_test(axelrod.Defector(), expected_actions = actions,
seed=8)
Expand Down
12 changes: 12 additions & 0 deletions axelrod/tests/unit/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def test_score(self):
self.assertEqual(self.game.score((C, D)), (0, 5))
self.assertEqual(self.game.score((D, C)), (5, 0))

def test_equality(self):
game_1 = Game(1, 2, 3, 4)
game_2 = Game(1, 2, 3, 4)
not_equal = Game()

self.assertEqual(game_1, game_2)
self.assertNotEqual(not_equal, game_1)

self.assertEqual(Game(), Game())

self.assertNotEqual(Game(), 'wrong class')

@given(r=integers(), p=integers(), s=integers(), t=integers())
def test_property_init(self, r, p, s, t):
"""Use the hypothesis library to test init"""
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ The Prisoner's Dilemma
The `Prisoner's dilemma <http://en.wikipedia.org/wiki/Prisoner%27s_dilemma>`_ is the simple two player game shown below:

+----------+---------------+---------------+
| | Cooperate | MyCooperator |
| | Cooperate | Defect |
+==========+===============+===============+
|Cooperate | (3,3) | (0,5) |
+----------+---------------+---------------+
|MyCooperator | (5,0) | (1,1) |
|Defect | (5,0) | (1,1) |
+----------+---------------+---------------+

If both players cooperate they will each go to prison for 2 years and receive an
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/play_contexts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ generic Prisoner's dilemma:


+----------+---------------+---------------+
| | Cooperate | MyCooperator |
| | Cooperate | Defect |
+==========+===============+===============+
|Cooperate | (R,R) | (S,T) |
+----------+---------------+---------------+
|MyCooperator | (T,S) | (P,P) |
|Defect | (T,S) | (P,P) |
+----------+---------------+---------------+

For the above to constitute a Prisoner's dilemma, the following must hold:
Expand Down
Binary file removed omfg.png
Binary file not shown.

0 comments on commit 01c31c9

Please sign in to comment.