Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Slow TF2T #659

Merged
merged 9 commits into from
Jul 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from .titfortat import (
TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat,
SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats,
OmegaTFT, Gradual, ContriteTitForTat)
OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats)


# Note: Meta* strategies are handled in .__init__.py
Expand Down Expand Up @@ -166,6 +166,7 @@
Ripoff,
RiskyQLearner,
Shubik,
SlowTitForTwoTats,
SneakyTitForTat,
SoftGrudger,
SoftJoss,
Expand Down
33 changes: 33 additions & 0 deletions axelrod/strategies/titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,36 @@ def reset(self):
Player.reset(self)
self.contrite = False
self._recorded_history = []


class SlowTitForTwoTats(Player):
"""
A player plays C twice, then if the opponent plays the same move twice,
plays that move
"""

name = 'Slow Tit For Two Tats'
classifier = {
'memory_depth': 2,
'stochastic': False,
'makes_use_of': set(),
'inspects_source': False,
'manipulates_source': False,
'manipulates_state': False
}

def strategy(self, opponent):

#Start with two cooperations
if len(self.history) < 2:
return C

#Mimic if opponent plays the same move twice
if opponent.history[-2] == opponent.history[-1]:
return opponent.history[-1]

#Otherwise cooperate
return C



1 change: 1 addition & 0 deletions axelrod/tests/unit/test_punisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ def test_reset_method(self):
self.assertEqual(P1.history, [])
self.assertEqual(P1.grudged, False)
self.assertEqual(P1.grudge_memory, 0)

27 changes: 27 additions & 0 deletions axelrod/tests/unit/test_titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,35 @@ def test_strategy_with_noise(self):
self.assertEqual(opponent.history, [C, D, D, D])
self.assertFalse(ctft.contrite)


def test_reset_cleans_all(self):
p = self.player()
p.contrite = True
p.reset()
self.assertFalse(p.contrite)

class TestSlowTitForTwoTats(TestPlayer):

name = "Slow Tit For Two Tats"
player = axelrod.SlowTitForTwoTats
expected_classifier = {
'memory_depth': 2,
'stochastic': False,
'makes_use_of': set(),
'inspects_source': False,
'manipulates_source': False,
'manipulates_state': False
}

def test_strategy(self):
"""Starts by cooperating."""
self.first_play_test(C)

def test_effect_of_strategy(self):
"""If opponent plays the same move twice, repeats last action of opponent history."""
self.responses_test([C]*2, [C, C], [C])
self.responses_test([C]*3, [C, D, C], [C])
self.responses_test([C]*3, [C, D, D], [D])