From d4dbe8af0e442fd1db4e0984966dc0614076b23e Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Sun, 3 Jul 2016 14:32:24 -0400 Subject: [PATCH 1/8] Added slow_tft in tft --- axelrod/strategies/titfortat.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index fef735956..169890d16 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -386,3 +386,34 @@ def reset(self): Player.reset(self) self.contrite = False self._recorded_history = [] + +class SlowTitForTat(Player): + """ + A player co-operates twice, then if the opponent makes the same move twice, + the player mimics its move + """ + + name = 'Slow Tit For Tat' + classifier = { + 'memory_depth': 2, # Four-Vector = (1.,0.,1.,0.) + 'stochastic': False, + 'makes_use_of': set(), + 'inspects_source': False, + 'manipulates_source': False, + 'manipulates_state': False + } + + def strategy(self, opponent): + + #Co-operate twice + if self.history[-1] == C: + return C + + #If opponent makes the same move twice, mimc + if opponent.history[-2] == opponent.history [-1]: + return opponent.history[-1] + + return C + + + From 3ee3876b08a403d232ce537b07ce16f6a0e03455 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Tue, 5 Jul 2016 21:02:40 -0400 Subject: [PATCH 2/8] Added slow tit for two tats --- axelrod/strategies/titfortat.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index 169890d16..6a9c27d90 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -387,13 +387,13 @@ def reset(self): self.contrite = False self._recorded_history = [] -class SlowTitForTat(Player): + +class SoftTitForTwoTats(Player): """ - A player co-operates twice, then if the opponent makes the same move twice, - the player mimics its move + A player co-operates except for when the opponent defects twice """ - name = 'Slow Tit For Tat' + name = 'Soft Tit For Two Tats' classifier = { 'memory_depth': 2, # Four-Vector = (1.,0.,1.,0.) 'stochastic': False, @@ -404,13 +404,10 @@ class SlowTitForTat(Player): } def strategy(self, opponent): - - #Co-operate twice - if self.history[-1] == C: + if len(self.history) == 0: return C - #If opponent makes the same move twice, mimc - if opponent.history[-2] == opponent.history [-1]: + if opponent.history[-2] == [D, D]: return opponent.history[-1] return C From f4c1c8aeef0596e50332255e7522c37f7a8e60a0 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Tue, 5 Jul 2016 21:13:57 -0400 Subject: [PATCH 3/8] Corrected SoftTFT and previous commit typo --- axelrod/strategies/titfortat.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index 169890d16..da8cf25f7 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -387,13 +387,13 @@ def reset(self): self.contrite = False self._recorded_history = [] -class SlowTitForTat(Player): + +class SoftTitForTwoTats(Player): """ - A player co-operates twice, then if the opponent makes the same move twice, - the player mimics its move + A player co-operates except for when the opponent defects twice """ - name = 'Slow Tit For Tat' + name = 'Soft Tit For Two Tats' classifier = { 'memory_depth': 2, # Four-Vector = (1.,0.,1.,0.) 'stochastic': False, @@ -404,14 +404,11 @@ class SlowTitForTat(Player): } def strategy(self, opponent): - - #Co-operate twice - if self.history[-1] == C: + if len(self.history) == 0: return C - #If opponent makes the same move twice, mimc - if opponent.history[-2] == opponent.history [-1]: - return opponent.history[-1] + if opponent.history[-2] == [D, D]: + return D return C From 0cf858d14aa0bd5d13c7db1298983d6d322a4b44 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Tue, 5 Jul 2016 21:44:56 -0400 Subject: [PATCH 4/8] Corrected SoftTF2T and previous commit msg --- axelrod/strategies/_strategies.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index 004108fc6..af8f47534 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -56,7 +56,7 @@ from .titfortat import ( TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat, SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats, - OmegaTFT, Gradual, ContriteTitForTat) + OmegaTFT, Gradual, ContriteTitForTat, SoftTitForTwoTats) # Note: Meta* strategies are handled in .__init__.py @@ -166,6 +166,7 @@ Ripoff, RiskyQLearner, Shubik, + SoftTitForTwoTats, SneakyTitForTat, SoftGrudger, SoftJoss, From b07a4b35390ca8cd920c853576b56a4e0b618965 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Sat, 16 Jul 2016 11:28:59 -0400 Subject: [PATCH 5/8] Added strategy Slow TF2T --- axelrod/strategies/_strategies.py | 4 ++-- axelrod/strategies/titfortat.py | 18 ++++++++++-------- axelrod/tests/unit/test_punisher.py | 1 + axelrod/tests/unit/test_titfortat.py | 5 +++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index af8f47534..7362e44e3 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -56,7 +56,7 @@ from .titfortat import ( TitForTat, TitFor2Tats, TwoTitsForTat, Bully, SneakyTitForTat, SuspiciousTitForTat, AntiTitForTat, HardTitForTat, HardTitFor2Tats, - OmegaTFT, Gradual, ContriteTitForTat, SoftTitForTwoTats) + OmegaTFT, Gradual, ContriteTitForTat, SlowTitForTwoTats) # Note: Meta* strategies are handled in .__init__.py @@ -166,7 +166,7 @@ Ripoff, RiskyQLearner, Shubik, - SoftTitForTwoTats, + SlowTitForTwoTats, SneakyTitForTat, SoftGrudger, SoftJoss, diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index da8cf25f7..e5921f9af 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -388,12 +388,13 @@ def reset(self): self._recorded_history = [] -class SoftTitForTwoTats(Player): +class SlowTitForTwoTats(Player): """ - A player co-operates except for when the opponent defects twice + A player that plays [c,c], then if the opponent plays the same move twice, + plays that move """ - name = 'Soft Tit For Two Tats' + name = 'Slow Tit For Two Tats' classifier = { 'memory_depth': 2, # Four-Vector = (1.,0.,1.,0.) 'stochastic': False, @@ -404,12 +405,13 @@ class SoftTitForTwoTats(Player): } def strategy(self, opponent): - if len(self.history) == 0: + #Play [c, c] + if len(self.history)<2: return C - - if opponent.history[-2] == [D, D]: - return D - + #Mimic if opponent plays same move twice + if opponent.history[-2] == opponent.history[-1]: + return opponent.history[-1] + #Otherwise cooperate return C diff --git a/axelrod/tests/unit/test_punisher.py b/axelrod/tests/unit/test_punisher.py index 29451c37b..7aabf2950 100644 --- a/axelrod/tests/unit/test_punisher.py +++ b/axelrod/tests/unit/test_punisher.py @@ -116,3 +116,4 @@ def test_reset_method(self): self.assertEqual(P1.history, []) self.assertEqual(P1.grudged, False) self.assertEqual(P1.grudge_memory, 0) + \ No newline at end of file diff --git a/axelrod/tests/unit/test_titfortat.py b/axelrod/tests/unit/test_titfortat.py index 33c606ae6..c9ead4585 100644 --- a/axelrod/tests/unit/test_titfortat.py +++ b/axelrod/tests/unit/test_titfortat.py @@ -432,8 +432,13 @@ 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) + + + + \ No newline at end of file From 169f4877c7ed93c0ef3d5e6ee82047ea3f15a709 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Sat, 16 Jul 2016 13:22:11 -0400 Subject: [PATCH 6/8] Added changes from last PR review, added tests --- axelrod/strategies/titfortat.py | 4 ++-- axelrod/tests/unit/test_titfortat.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index e5921f9af..aab5fa884 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -390,13 +390,13 @@ def reset(self): class SlowTitForTwoTats(Player): """ - A player that plays [c,c], then if the opponent plays the same move twice, + 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, # Four-Vector = (1.,0.,1.,0.) + 'memory_depth': 2, 'stochastic': False, 'makes_use_of': set(), 'inspects_source': False, diff --git a/axelrod/tests/unit/test_titfortat.py b/axelrod/tests/unit/test_titfortat.py index c9ead4585..6d39a52d3 100644 --- a/axelrod/tests/unit/test_titfortat.py +++ b/axelrod/tests/unit/test_titfortat.py @@ -439,6 +439,28 @@ def test_reset_cleans_all(self): 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]) \ No newline at end of file From 9072fd23c3ea4b4c29d7eef7a7f217a15301bca8 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Sat, 16 Jul 2016 13:31:19 -0400 Subject: [PATCH 7/8] PEP8 correction --- axelrod/strategies/titfortat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index aab5fa884..cb8d7f6c9 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -405,8 +405,9 @@ class SlowTitForTwoTats(Player): } def strategy(self, opponent): + #Play [c, c] - if len(self.history)<2: + if len(self.history) < 2: return C #Mimic if opponent plays same move twice if opponent.history[-2] == opponent.history[-1]: From b1a015a3244374c730ee92a65ac36ac34ee3a2e6 Mon Sep 17 00:00:00 2001 From: Ranjini Das Date: Sat, 16 Jul 2016 14:19:38 -0400 Subject: [PATCH 8/8] Changed comment to #Start with two cooperations --- axelrod/strategies/titfortat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index cb8d7f6c9..6086ca2a9 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -406,12 +406,14 @@ class SlowTitForTwoTats(Player): def strategy(self, opponent): - #Play [c, c] + #Start with two cooperations if len(self.history) < 2: return C - #Mimic if opponent plays same move twice + + #Mimic if opponent plays the same move twice if opponent.history[-2] == opponent.history[-1]: return opponent.history[-1] + #Otherwise cooperate return C