From abd4ffa107e430efbdd7dd16546d50a3d93342bd Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Wed, 15 Mar 2017 12:05:59 +0000 Subject: [PATCH 1/8] Add condition for is_alternator to return false for junk history --- axelrod/strategies/hunter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axelrod/strategies/hunter.py b/axelrod/strategies/hunter.py index 8b5fff2b3..4f1bb99e8 100644 --- a/axelrod/strategies/hunter.py +++ b/axelrod/strategies/hunter.py @@ -49,7 +49,7 @@ def strategy(self, opponent: Player) -> Action: def is_alternator(history: List[Action]) -> bool: for i in range(len(history) - 1): - if history[i] == history[i + 1]: + if history[i] == history[i + 1] or history[i] not in (C, D): return False return True From 310e66ef8e202067be63652bd15cdc365d5b2ade Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Wed, 15 Mar 2017 12:06:28 +0000 Subject: [PATCH 2/8] Use junk history for test concerning lengthy history --- axelrod/tests/strategies/test_meta.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/axelrod/tests/strategies/test_meta.py b/axelrod/tests/strategies/test_meta.py index 065c3e71c..542714c17 100644 --- a/axelrod/tests/strategies/test_meta.py +++ b/axelrod/tests/strategies/test_meta.py @@ -248,7 +248,9 @@ def test_strategy(self): self.responses_test([D], [C, C, C, C], [C, C, C, C]) # After long histories tit-for-tat should come into play. - self.responses_test([D], [C] * 101, [C] * 100 + [D]) + letters = 'ABEFGHIJKLMNOPQRSTUVWXYZ' + junk_history = [random.choice(letters) for _ in range(101)] + self.responses_test([D], junk_history, junk_history[:100] + [D]) # All these others, however, should trigger a defection for the hunter. self.responses_test([D], [C] * 4, [D] * 4) From 865a996b5a6c83e361582e8ffefe9b7beed92f1d Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Wed, 15 Mar 2017 12:40:25 +0000 Subject: [PATCH 3/8] Add comment to explain need for junk history --- axelrod/tests/strategies/test_meta.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/axelrod/tests/strategies/test_meta.py b/axelrod/tests/strategies/test_meta.py index 542714c17..84e5b10e4 100644 --- a/axelrod/tests/strategies/test_meta.py +++ b/axelrod/tests/strategies/test_meta.py @@ -248,6 +248,12 @@ def test_strategy(self): self.responses_test([D], [C, C, C, C], [C, C, C, C]) # After long histories tit-for-tat should come into play. + # We generate a 'junk' history of length 101 in order to avoid the + # hunters triggering a defection as that overrides the tit-for-tat + # action. + # A genuine history (based on C or D only) which does trigger any of + # hunters is extremely difficult to identify. None of the strategies + # as at 14-Mar-2017 avoids doing so. letters = 'ABEFGHIJKLMNOPQRSTUVWXYZ' junk_history = [random.choice(letters) for _ in range(101)] self.responses_test([D], junk_history, junk_history[:100] + [D]) From b52819b447788b6ff5a47c61cda35a082b9d20da Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Wed, 15 Mar 2017 12:41:17 +0000 Subject: [PATCH 4/8] Fix typos --- axelrod/tests/strategies/test_meta.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/axelrod/tests/strategies/test_meta.py b/axelrod/tests/strategies/test_meta.py index 84e5b10e4..1650fbdaa 100644 --- a/axelrod/tests/strategies/test_meta.py +++ b/axelrod/tests/strategies/test_meta.py @@ -251,9 +251,9 @@ def test_strategy(self): # We generate a 'junk' history of length 101 in order to avoid the # hunters triggering a defection as that overrides the tit-for-tat # action. - # A genuine history (based on C or D only) which does trigger any of - # hunters is extremely difficult to identify. None of the strategies - # as at 14-Mar-2017 avoids doing so. + # A genuine history (based on C or D only) which does not trigger any + # of the hunters is extremely difficult to identify. None of the + # strategies as at 14-Mar-2017 avoids doing so. letters = 'ABEFGHIJKLMNOPQRSTUVWXYZ' junk_history = [random.choice(letters) for _ in range(101)] self.responses_test([D], junk_history, junk_history[:100] + [D]) From 1d9d231ecb354c45fa5a5a8af86006cd4d5fd8f3 Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Thu, 16 Mar 2017 09:22:53 +0000 Subject: [PATCH 5/8] Add team argument to init method --- axelrod/strategies/meta.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/axelrod/strategies/meta.py b/axelrod/strategies/meta.py index 04842e7e2..df8d25962 100644 --- a/axelrod/strategies/meta.py +++ b/axelrod/strategies/meta.py @@ -235,11 +235,12 @@ class MetaHunterAggressive(MetaPlayer): 'manipulates_state': False } - def __init__(self): + def __init__(self, team=None): # This version uses CooperatorHunter - team = [DefectorHunter, AlternatorHunter, RandomHunter, - MathConstantHunter, CycleHunter, EventualCycleHunter, - CooperatorHunter] + if team is None: + team = [DefectorHunter, AlternatorHunter, RandomHunter, + MathConstantHunter, CycleHunter, EventualCycleHunter, + CooperatorHunter] super().__init__(team=team) From 84d5e847442eec87d7ba2cf4ab7c4a7f76c0cab2 Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Thu, 16 Mar 2017 09:23:16 +0000 Subject: [PATCH 6/8] Replace the junk history test with one using a denuded team --- axelrod/tests/strategies/test_meta.py | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/axelrod/tests/strategies/test_meta.py b/axelrod/tests/strategies/test_meta.py index 1650fbdaa..5d68a7e5d 100644 --- a/axelrod/tests/strategies/test_meta.py +++ b/axelrod/tests/strategies/test_meta.py @@ -247,17 +247,6 @@ def test_strategy(self): # defection self.responses_test([D], [C, C, C, C], [C, C, C, C]) - # After long histories tit-for-tat should come into play. - # We generate a 'junk' history of length 101 in order to avoid the - # hunters triggering a defection as that overrides the tit-for-tat - # action. - # A genuine history (based on C or D only) which does not trigger any - # of the hunters is extremely difficult to identify. None of the - # strategies as at 14-Mar-2017 avoids doing so. - letters = 'ABEFGHIJKLMNOPQRSTUVWXYZ' - junk_history = [random.choice(letters) for _ in range(101)] - self.responses_test([D], junk_history, junk_history[:100] + [D]) - # All these others, however, should trigger a defection for the hunter. self.responses_test([D], [C] * 4, [D] * 4) self.responses_test([D], [C] * 6, [C, D] * 3) @@ -266,6 +255,23 @@ def test_strategy(self): self.responses_test([D], [C] * 101, [C] * 101) self.responses_test([D], [C] * 101, [C] * 100 + [D]) + # To test the TFT action of the strategy after 100 turns, we need to + # remove two of the hunters from its team. + # It is almost impossible to identify a history which reach 100 turns + # without triggering one of the hunters in the default team. As at + # 16-Mar-2017, none of the strategies in the library does so. + team = [ + axelrod.DefectorHunter, + axelrod.AlternatorHunter, + axelrod.RandomHunter, + # axelrod.MathConstantHunter, + axelrod.CycleHunter, + axelrod.EventualCycleHunter, + # axelrod.CooperatorHunter + ] + self.responses_test( + [D], [C] * 101, [C] * 100 + [D], init_kwargs={'team': team}) + class TestMetaMajorityMemoryOne(TestMetaPlayer): name = "Meta Majority Memory One" From 18f5940b9c57abf64d93cca8e750b2c405348607 Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Thu, 16 Mar 2017 09:51:15 +0000 Subject: [PATCH 7/8] Correct typo --- axelrod/tests/strategies/test_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axelrod/tests/strategies/test_meta.py b/axelrod/tests/strategies/test_meta.py index 5d68a7e5d..21cc83b92 100644 --- a/axelrod/tests/strategies/test_meta.py +++ b/axelrod/tests/strategies/test_meta.py @@ -257,7 +257,7 @@ def test_strategy(self): # To test the TFT action of the strategy after 100 turns, we need to # remove two of the hunters from its team. - # It is almost impossible to identify a history which reach 100 turns + # It is almost impossible to identify a history which reaches 100 turns # without triggering one of the hunters in the default team. As at # 16-Mar-2017, none of the strategies in the library does so. team = [ From 0ba0d94be69a182e30c597660c4ff180625e65e2 Mon Sep 17 00:00:00 2001 From: Owen Campbell Date: Thu, 16 Mar 2017 09:51:34 +0000 Subject: [PATCH 8/8] Revert "Add condition for is_alternator to return false for junk history" This reverts commit abd4ffa107e430efbdd7dd16546d50a3d93342bd. --- axelrod/strategies/hunter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axelrod/strategies/hunter.py b/axelrod/strategies/hunter.py index 4f1bb99e8..8b5fff2b3 100644 --- a/axelrod/strategies/hunter.py +++ b/axelrod/strategies/hunter.py @@ -49,7 +49,7 @@ def strategy(self, opponent: Player) -> Action: def is_alternator(history: List[Action]) -> bool: for i in range(len(history) - 1): - if history[i] == history[i + 1] or history[i] not in (C, D): + if history[i] == history[i + 1]: return False return True