From ab84b8344911dbfe64a811145ef74aa2898ee6fc Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sun, 12 Apr 2020 02:51:53 -0700 Subject: [PATCH 1/8] Add makes_use_of function --- axelrod/makes_use_of.py | 18 ++++++++++ axelrod/tests/unit/test_makes_use_of.py | 47 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 axelrod/makes_use_of.py create mode 100644 axelrod/tests/unit/test_makes_use_of.py diff --git a/axelrod/makes_use_of.py b/axelrod/makes_use_of.py new file mode 100644 index 000000000..d55fe3f9a --- /dev/null +++ b/axelrod/makes_use_of.py @@ -0,0 +1,18 @@ +import inspect +import re +from typing import Set, Text, Type + +from axelrod.player import Player + + +def makes_use_of(player: Type[Player]) -> Set[Text]: + result = set() + for method in inspect.getmembers(player, inspect.ismethod): + if method[0] == "__init__": + continue + method_code = inspect.getsource(method[1]) + attr_string = r"self.match_attributes\[\"(\w+)\"\]" + all_attrs = re.findall(attr_string, method_code) + for attr in all_attrs: + result.add(attr) + return result diff --git a/axelrod/tests/unit/test_makes_use_of.py b/axelrod/tests/unit/test_makes_use_of.py new file mode 100644 index 000000000..5f41b06de --- /dev/null +++ b/axelrod/tests/unit/test_makes_use_of.py @@ -0,0 +1,47 @@ +"""Tests for makes_use_of.""" + +import unittest + +import axelrod as axl +from axelrod.makes_use_of import makes_use_of + + +class TestMakesUseOfLengthAndGamePlayer(axl.Player): + """ + Should have some function that uses length + """ + + def first_function(self): # pragma: no cover + x = 1 + 2 + x * 5 + + def second_function(self): # pragma: no cover + # We put this in the second function to make sure both are checked. + x = 1 + self.match_attributes["length"] + + # Should only add once. + y = 2 + self.match_attributes["length"] + + # Should also add game. + self.match_attributes["game"] + + +class TestMakesUseOfNothingPlayer(axl.Player): + """ + Doesn't use match_attributes + """ + + def only_function(self): # pragma: no cover + 1 + 2 + 3 + print("=6") + + +class TestMakesUseOf(unittest.TestCase): + def test_makes_use_of_length_and_game(self): + self.assertEqual( + makes_use_of(TestMakesUseOfLengthAndGamePlayer()), + {"length", "game"}, + ) + + def test_makes_use_of_empty(self): + self.assertEqual(makes_use_of(TestMakesUseOfNothingPlayer()), set()) From 53600a9a58560db49f44a6ff0649d9e4b8021bd5 Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sun, 12 Apr 2020 03:05:44 -0700 Subject: [PATCH 2/8] Remove makes_use_of from classifiers --- axelrod/strategies/adaptive.py | 1 - axelrod/strategies/adaptor.py | 1 - axelrod/strategies/alternator.py | 1 - axelrod/strategies/ann.py | 1 - axelrod/strategies/apavlov.py | 2 -- axelrod/strategies/appeaser.py | 1 - axelrod/strategies/averagecopier.py | 2 -- axelrod/strategies/axelrod_first.py | 11 ---------- axelrod/strategies/axelrod_second.py | 24 --------------------- axelrod/strategies/backstabber.py | 2 -- axelrod/strategies/better_and_better.py | 1 - axelrod/strategies/bush_mosteller.py | 1 - axelrod/strategies/calculator.py | 1 - axelrod/strategies/cooperator.py | 2 -- axelrod/strategies/cycler.py | 2 -- axelrod/strategies/darwin.py | 1 - axelrod/strategies/dbs.py | 1 - axelrod/strategies/defector.py | 2 -- axelrod/strategies/doubler.py | 1 - axelrod/strategies/finite_state_machines.py | 19 ---------------- axelrod/strategies/forgiver.py | 2 -- axelrod/strategies/gambler.py | 2 -- axelrod/strategies/geller.py | 3 --- axelrod/strategies/gobymajority.py | 1 - axelrod/strategies/gradualkiller.py | 1 - axelrod/strategies/grudger.py | 8 ------- axelrod/strategies/grumpy.py | 1 - axelrod/strategies/handshake.py | 1 - axelrod/strategies/hmm.py | 2 -- axelrod/strategies/human.py | 1 - axelrod/strategies/hunter.py | 6 ------ axelrod/strategies/inverse.py | 1 - axelrod/strategies/lookerup.py | 1 - axelrod/strategies/mathematicalconstants.py | 1 - axelrod/strategies/memoryone.py | 5 ----- axelrod/strategies/memorytwo.py | 6 +----- axelrod/strategies/meta.py | 5 ----- axelrod/strategies/mindcontrol.py | 3 --- axelrod/strategies/mindreader.py | 3 --- axelrod/strategies/mutual.py | 3 --- axelrod/strategies/negation.py | 1 - axelrod/strategies/oncebitten.py | 3 --- axelrod/strategies/prober.py | 9 -------- axelrod/strategies/punisher.py | 4 ---- axelrod/strategies/qlearner.py | 1 - axelrod/strategies/rand.py | 1 - axelrod/strategies/resurrection.py | 2 -- axelrod/strategies/retaliate.py | 2 -- axelrod/strategies/revised_downing.py | 1 - axelrod/strategies/selfsteem.py | 1 - axelrod/strategies/sequence_player.py | 2 -- axelrod/strategies/shortmem.py | 1 - axelrod/strategies/stalker.py | 1 - axelrod/strategies/titfortat.py | 22 ------------------- axelrod/strategies/verybad.py | 1 - axelrod/strategies/worse_and_worse.py | 4 ---- axelrod/strategies/zero_determinant.py | 1 - 57 files changed, 1 insertion(+), 189 deletions(-) diff --git a/axelrod/strategies/adaptive.py b/axelrod/strategies/adaptive.py index bef1b8dac..02e930162 100644 --- a/axelrod/strategies/adaptive.py +++ b/axelrod/strategies/adaptive.py @@ -20,7 +20,6 @@ class Adaptive(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(["game"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/adaptor.py b/axelrod/strategies/adaptor.py index 2648b2704..cfed31416 100644 --- a/axelrod/strategies/adaptor.py +++ b/axelrod/strategies/adaptor.py @@ -32,7 +32,6 @@ class AbstractAdaptor(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/alternator.py b/axelrod/strategies/alternator.py index 6ed3605a4..4147f1af7 100644 --- a/axelrod/strategies/alternator.py +++ b/axelrod/strategies/alternator.py @@ -18,7 +18,6 @@ class Alternator(Player): classifier = { "memory_depth": 1, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/ann.py b/axelrod/strategies/ann.py index 2d3a1bc85..42a1ec20e 100644 --- a/axelrod/strategies/ann.py +++ b/axelrod/strategies/ann.py @@ -184,7 +184,6 @@ class ANN(Player): "memory_depth": float("inf"), "stochastic": False, "inspects_source": False, - "makes_use_of": set(), "manipulates_source": False, "manipulates_state": False, "long_run_time": False, diff --git a/axelrod/strategies/apavlov.py b/axelrod/strategies/apavlov.py index 0b54b10a9..3e3b17525 100644 --- a/axelrod/strategies/apavlov.py +++ b/axelrod/strategies/apavlov.py @@ -22,7 +22,6 @@ class APavlov2006(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -86,7 +85,6 @@ class APavlov2011(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/appeaser.py b/axelrod/strategies/appeaser.py index 790b8439d..fd7b224f0 100644 --- a/axelrod/strategies/appeaser.py +++ b/axelrod/strategies/appeaser.py @@ -19,7 +19,6 @@ class Appeaser(Player): classifier = { "memory_depth": float("inf"), # Depends on internal memory. "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/averagecopier.py b/axelrod/strategies/averagecopier.py index 597407c61..7ee36ddbd 100644 --- a/axelrod/strategies/averagecopier.py +++ b/axelrod/strategies/averagecopier.py @@ -19,7 +19,6 @@ class AverageCopier(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -47,7 +46,6 @@ class NiceAverageCopier(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/axelrod_first.py b/axelrod/strategies/axelrod_first.py index f9dab0b94..983320fc8 100644 --- a/axelrod/strategies/axelrod_first.py +++ b/axelrod/strategies/axelrod_first.py @@ -47,7 +47,6 @@ class FirstByDavis(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -236,7 +235,6 @@ class FirstByDowning(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -311,7 +309,6 @@ class FirstByFeld(Player): classifier = { "memory_depth": 200, # Varies actually, eventually becomes depth 1 "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -403,7 +400,6 @@ class FirstByGraaskamp(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -479,7 +475,6 @@ class FirstByGrofman(Player): classifier = { "memory_depth": 1, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -580,7 +575,6 @@ class FirstByNydegger(Player): classifier = { "memory_depth": 3, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -667,7 +661,6 @@ class FirstByShubik(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -738,7 +731,6 @@ class FirstByTullock(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -794,7 +786,6 @@ class FirstByAnonymous(Player): classifier = { "memory_depth": 0, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -839,7 +830,6 @@ class FirstBySteinAndRapoport(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -927,7 +917,6 @@ class FirstByTidemanAndChieruzzi(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"game", "length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/axelrod_second.py b/axelrod/strategies/axelrod_second.py index 50e4e18ee..4029d552a 100644 --- a/axelrod/strategies/axelrod_second.py +++ b/axelrod/strategies/axelrod_second.py @@ -36,7 +36,6 @@ class SecondByChampion(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -79,7 +78,6 @@ class SecondByEatherley(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -120,7 +118,6 @@ class SecondByTester(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -173,7 +170,6 @@ class SecondByGladstein(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -321,7 +317,6 @@ class SecondByTranquilizer(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -452,7 +447,6 @@ class SecondByGrofman(Player): classifier = { "memory_depth": 8, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -516,7 +510,6 @@ class SecondByKluepfel(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -628,7 +621,6 @@ class SecondByBorufsen(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -764,7 +756,6 @@ class SecondByCave(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -815,7 +806,6 @@ class SecondByWmAdams(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -862,7 +852,6 @@ class SecondByGraaskampKatzen(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(["game"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -945,7 +934,6 @@ class SecondByWeiner(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1098,7 +1086,6 @@ class SecondByHarrington(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1372,7 +1359,6 @@ class SecondByTidemanAndChieruzzi(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1468,7 +1454,6 @@ class SecondByGetzler(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1512,7 +1497,6 @@ class SecondByLeyvraz(Player): classifier = { "memory_depth": 3, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1562,7 +1546,6 @@ class SecondByWhite(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1600,7 +1583,6 @@ class SecondByBlack(Player): classifier = { "memory_depth": 5, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1672,7 +1654,6 @@ class SecondByRichardHufford(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1769,7 +1750,6 @@ class SecondByYamachi(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1856,7 +1836,6 @@ class SecondByColbert(FSMPlayer): classifier = { "memory_depth": 4, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1919,7 +1898,6 @@ class SecondByMikkelson(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1993,7 +1971,6 @@ class SecondByRowsam(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set("game"), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -2088,7 +2065,6 @@ class SecondByAppold(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/backstabber.py b/axelrod/strategies/backstabber.py index b3a522ae2..0d9d821d9 100644 --- a/axelrod/strategies/backstabber.py +++ b/axelrod/strategies/backstabber.py @@ -20,7 +20,6 @@ class BackStabber(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -50,7 +49,6 @@ class DoubleCrosser(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/better_and_better.py b/axelrod/strategies/better_and_better.py index 1af697a00..cca647a9c 100644 --- a/axelrod/strategies/better_and_better.py +++ b/axelrod/strategies/better_and_better.py @@ -19,7 +19,6 @@ class BetterAndBetter(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/bush_mosteller.py b/axelrod/strategies/bush_mosteller.py index d6ed5adf3..9c59929a9 100644 --- a/axelrod/strategies/bush_mosteller.py +++ b/axelrod/strategies/bush_mosteller.py @@ -27,7 +27,6 @@ class BushMosteller(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(["game"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/calculator.py b/axelrod/strategies/calculator.py index 8ac9b59d0..5353a4b2e 100644 --- a/axelrod/strategies/calculator.py +++ b/axelrod/strategies/calculator.py @@ -22,7 +22,6 @@ class Calculator(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/cooperator.py b/axelrod/strategies/cooperator.py index 6435a3504..61d4fd4ca 100644 --- a/axelrod/strategies/cooperator.py +++ b/axelrod/strategies/cooperator.py @@ -18,7 +18,6 @@ class Cooperator(Player): classifier = { "memory_depth": 0, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -43,7 +42,6 @@ class TrickyCooperator(Player): classifier = { "memory_depth": 10, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/cycler.py b/axelrod/strategies/cycler.py index 509141717..5d450d225 100644 --- a/axelrod/strategies/cycler.py +++ b/axelrod/strategies/cycler.py @@ -25,7 +25,6 @@ class AntiCycler(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -67,7 +66,6 @@ class Cycler(Player): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/darwin.py b/axelrod/strategies/darwin.py index 93db009eb..07a8bdae6 100644 --- a/axelrod/strategies/darwin.py +++ b/axelrod/strategies/darwin.py @@ -40,7 +40,6 @@ class Darwin(Player): "stochastic": False, "inspects_source": True, # Checks to see if opponent is using simulated matches. "long_run_time": False, - "makes_use_of": set(), "manipulates_source": False, "manipulates_state": True, # Does not reset properly. } diff --git a/axelrod/strategies/dbs.py b/axelrod/strategies/dbs.py index dafdb8ec2..e91eb0776 100644 --- a/axelrod/strategies/dbs.py +++ b/axelrod/strategies/dbs.py @@ -25,7 +25,6 @@ class DBS(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": True, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/defector.py b/axelrod/strategies/defector.py index 4e05184f8..7b4831443 100644 --- a/axelrod/strategies/defector.py +++ b/axelrod/strategies/defector.py @@ -18,7 +18,6 @@ class Defector(Player): classifier = { "memory_depth": 0, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -42,7 +41,6 @@ class TrickyDefector(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/doubler.py b/axelrod/strategies/doubler.py index 27c9ad847..4ed6b5ad0 100644 --- a/axelrod/strategies/doubler.py +++ b/axelrod/strategies/doubler.py @@ -18,7 +18,6 @@ class Doubler(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/finite_state_machines.py b/axelrod/strategies/finite_state_machines.py index e7bdd7f63..616c7f2e4 100644 --- a/axelrod/strategies/finite_state_machines.py +++ b/axelrod/strategies/finite_state_machines.py @@ -100,7 +100,6 @@ class FSMPlayer(Player): classifier = { "memory_depth": 1, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -133,7 +132,6 @@ class EvolvableFSMPlayer(FSMPlayer, EvolvablePlayer): classifier = { "memory_depth": 1, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -311,7 +309,6 @@ class Fortress3(FSMPlayer): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -350,7 +347,6 @@ class Fortress4(FSMPlayer): classifier = { "memory_depth": 3, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -388,7 +384,6 @@ class Predator(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -434,7 +429,6 @@ class Pun1(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -463,7 +457,6 @@ class Raider(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -500,7 +493,6 @@ class Ripoff(FSMPlayer): classifier = { "memory_depth": 3, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -535,7 +527,6 @@ class UsuallyCooperates(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -563,7 +554,6 @@ class UsuallyDefects(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -591,7 +581,6 @@ class SolutionB1(FSMPlayer): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -627,7 +616,6 @@ class SolutionB5(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -668,7 +656,6 @@ class Thumper(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -696,7 +683,6 @@ class EvolvedFSM4(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -734,7 +720,6 @@ class EvolvedFSM16(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -792,7 +777,6 @@ class EvolvedFSM16Noise05(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -852,7 +836,6 @@ class TF1(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -913,7 +896,6 @@ class TF2(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -970,7 +952,6 @@ class TF3(FSMPlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/forgiver.py b/axelrod/strategies/forgiver.py index 4d2cb7ed8..277890643 100644 --- a/axelrod/strategies/forgiver.py +++ b/axelrod/strategies/forgiver.py @@ -18,7 +18,6 @@ class Forgiver(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -50,7 +49,6 @@ class ForgivingTitForTat(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/gambler.py b/axelrod/strategies/gambler.py index f127ce0f4..7077f1cec 100644 --- a/axelrod/strategies/gambler.py +++ b/axelrod/strategies/gambler.py @@ -33,7 +33,6 @@ class Gambler(LookerUp): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -204,7 +203,6 @@ class ZDMem2(Gambler): classifier = { "memory_depth": 2, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/geller.py b/axelrod/strategies/geller.py index 8343f8aa1..d86ed91c7 100644 --- a/axelrod/strategies/geller.py +++ b/axelrod/strategies/geller.py @@ -42,7 +42,6 @@ class Geller(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": False, @@ -77,7 +76,6 @@ class GellerCooperator(Geller): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": False, @@ -105,7 +103,6 @@ class GellerDefector(Geller): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": False, diff --git a/axelrod/strategies/gobymajority.py b/axelrod/strategies/gobymajority.py index e79efca0a..7617b571f 100644 --- a/axelrod/strategies/gobymajority.py +++ b/axelrod/strategies/gobymajority.py @@ -33,7 +33,6 @@ class GoByMajority(Player): classifier = { "stochastic": False, "inspects_source": False, - "makes_use_of": set(), "long_run_time": False, "manipulates_source": False, "manipulates_state": False, diff --git a/axelrod/strategies/gradualkiller.py b/axelrod/strategies/gradualkiller.py index 975f43c52..d421d06a2 100644 --- a/axelrod/strategies/gradualkiller.py +++ b/axelrod/strategies/gradualkiller.py @@ -24,7 +24,6 @@ class GradualKiller(Player): classifier = { "memory_depth": float("Inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/grudger.py b/axelrod/strategies/grudger.py index 61215bb9a..bbbb0633f 100644 --- a/axelrod/strategies/grudger.py +++ b/axelrod/strategies/grudger.py @@ -25,7 +25,6 @@ class Grudger(Player): classifier = { "memory_depth": float('inf'), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -55,7 +54,6 @@ class ForgetfulGrudger(Player): classifier = { "memory_depth": 10, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -99,7 +97,6 @@ class OppositeGrudger(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -128,7 +125,6 @@ class Aggravater(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -157,7 +153,6 @@ class SoftGrudger(Player): classifier = { "memory_depth": 6, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -201,7 +196,6 @@ class GrudgerAlternator(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -233,7 +227,6 @@ class EasyGo(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -266,7 +259,6 @@ class GeneralSoftGrudger(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/grumpy.py b/axelrod/strategies/grumpy.py index 6c4adaf5f..dd7bdc324 100644 --- a/axelrod/strategies/grumpy.py +++ b/axelrod/strategies/grumpy.py @@ -19,7 +19,6 @@ class Grumpy(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/handshake.py b/axelrod/strategies/handshake.py index 61a0d8219..41e02ff13 100644 --- a/axelrod/strategies/handshake.py +++ b/axelrod/strategies/handshake.py @@ -19,7 +19,6 @@ class Handshake(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/hmm.py b/axelrod/strategies/hmm.py index 8ae2ed811..693271ca8 100644 --- a/axelrod/strategies/hmm.py +++ b/axelrod/strategies/hmm.py @@ -134,7 +134,6 @@ class HMMPlayer(Player): classifier = { "memory_depth": 1, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -359,7 +358,6 @@ class EvolvedHMM5(HMMPlayer): classifier = { "memory_depth": 5, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/human.py b/axelrod/strategies/human.py index 753194248..b3a0e9564 100644 --- a/axelrod/strategies/human.py +++ b/axelrod/strategies/human.py @@ -54,7 +54,6 @@ class Human(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(["length", "game"]), "long_run_time": True, "inspects_source": True, "manipulates_source": False, diff --git a/axelrod/strategies/hunter.py b/axelrod/strategies/hunter.py index fe2b39fa1..51c6968d7 100644 --- a/axelrod/strategies/hunter.py +++ b/axelrod/strategies/hunter.py @@ -19,7 +19,6 @@ class DefectorHunter(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -44,7 +43,6 @@ class CooperatorHunter(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -76,7 +74,6 @@ class AlternatorHunter(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -111,7 +108,6 @@ class CycleHunter(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -169,7 +165,6 @@ class MathConstantHunter(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -218,7 +213,6 @@ class RandomHunter(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/inverse.py b/axelrod/strategies/inverse.py index 092309330..02f265c0e 100644 --- a/axelrod/strategies/inverse.py +++ b/axelrod/strategies/inverse.py @@ -18,7 +18,6 @@ class Inverse(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/lookerup.py b/axelrod/strategies/lookerup.py index b66d06293..d77ca32f0 100644 --- a/axelrod/strategies/lookerup.py +++ b/axelrod/strategies/lookerup.py @@ -302,7 +302,6 @@ class LookerUp(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/mathematicalconstants.py b/axelrod/strategies/mathematicalconstants.py index 8f88d1a2b..70295a405 100644 --- a/axelrod/strategies/mathematicalconstants.py +++ b/axelrod/strategies/mathematicalconstants.py @@ -18,7 +18,6 @@ class CotoDeRatio(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), # Long memory - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/memoryone.py b/axelrod/strategies/memoryone.py index 8fa4aeae6..6cdd41f49 100644 --- a/axelrod/strategies/memoryone.py +++ b/axelrod/strategies/memoryone.py @@ -28,7 +28,6 @@ class MemoryOnePlayer(Player): classifier = { "memory_depth": 1, # Memory-one Four-Vector "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -110,7 +109,6 @@ class WinStayLoseShift(MemoryOnePlayer): classifier = { "memory_depth": 1, # Memory-one Four-Vector "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -135,7 +133,6 @@ class WinShiftLoseStay(MemoryOnePlayer): classifier = { "memory_depth": 1, # Memory-one Four-Vector "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -162,7 +159,6 @@ class GTFT(MemoryOnePlayer): classifier = { "memory_depth": 1, # Memory-one Four-Vector "stochastic": True, - "makes_use_of": set(["game"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -312,7 +308,6 @@ class ALLCorALLD(Player): classifier = { "memory_depth": 1, # Memory-one Four-Vector (1, 1, 0, 0) "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/memorytwo.py b/axelrod/strategies/memorytwo.py index 3466256b3..d4aa8567c 100644 --- a/axelrod/strategies/memorytwo.py +++ b/axelrod/strategies/memorytwo.py @@ -47,7 +47,6 @@ class MemoryTwoPlayer(Player): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -127,7 +126,7 @@ class AON2(MemoryTwoPlayer): In [Hilbe2017]_ the following vectors are reported as "equivalent" to AON2 with their respective self-cooperation rate (note that these are not the same): - + 1. [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], self-cooperation rate: 0.952 2. [1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], self-cooperation @@ -151,7 +150,6 @@ class AON2(MemoryTwoPlayer): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -194,7 +192,6 @@ class DelayedAON1(MemoryTwoPlayer): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -224,7 +221,6 @@ class MEM2(Player): "memory_depth": float("inf"), "long_run_time": False, "stochastic": False, - "makes_use_of": set(), "inspects_source": False, "manipulates_source": False, "manipulates_state": False, diff --git a/axelrod/strategies/meta.py b/axelrod/strategies/meta.py index 09bebd26b..f71198aae 100644 --- a/axelrod/strategies/meta.py +++ b/axelrod/strategies/meta.py @@ -38,7 +38,6 @@ class MetaPlayer(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": True, "inspects_source": False, "manipulates_source": False, @@ -229,7 +228,6 @@ class MetaHunter(MetaPlayer): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -283,7 +281,6 @@ class MetaHunterAggressive(MetaPlayer): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -485,7 +482,6 @@ class MetaMixer(MetaPlayer): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": True, "inspects_source": False, "manipulates_source": False, @@ -610,7 +606,6 @@ class MemoryDecay(MetaPlayer): "memory_depth": float("inf"), "long_run_time": False, "stochastic": True, - "makes_use_of": set(), "inspects_source": False, "manipulates_source": False, "manipulates_state": False, diff --git a/axelrod/strategies/mindcontrol.py b/axelrod/strategies/mindcontrol.py index bdb3e974b..e1c3fa915 100644 --- a/axelrod/strategies/mindcontrol.py +++ b/axelrod/strategies/mindcontrol.py @@ -16,7 +16,6 @@ class MindController(Player): classifier = { "memory_depth": -10, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": True, # Finds out what opponent will do @@ -49,7 +48,6 @@ class MindWarper(Player): classifier = { "memory_depth": -10, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": True, # changes what opponent will do @@ -81,7 +79,6 @@ class MindBender(MindWarper): name = "Mind Bender" classifier = { "memory_depth": -10, - "makes_use_of": set(), "stochastic": False, "long_run_time": False, "inspects_source": False, diff --git a/axelrod/strategies/mindreader.py b/axelrod/strategies/mindreader.py index 723f503bf..c1f078e89 100644 --- a/axelrod/strategies/mindreader.py +++ b/axelrod/strategies/mindreader.py @@ -23,7 +23,6 @@ class MindReader(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": False, @@ -61,7 +60,6 @@ class ProtectedMindReader(MindReader): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": True, # Stops opponent's strategy @@ -91,7 +89,6 @@ class MirrorMindReader(ProtectedMindReader): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": True, # Reads and copies the source of the opponent "manipulates_source": True, # Changes own source dynamically diff --git a/axelrod/strategies/mutual.py b/axelrod/strategies/mutual.py index d537bbaad..1cd681195 100644 --- a/axelrod/strategies/mutual.py +++ b/axelrod/strategies/mutual.py @@ -17,7 +17,6 @@ class Desperate(Player): "memory_depth": 1, "long_run_time": False, "stochastic": True, - "makes_use_of": set(), "inspects_source": False, "manipulates_source": False, "manipulates_state": False, @@ -43,7 +42,6 @@ class Hopeless(Player): "memory_depth": 1, "long_run_time": False, "stochastic": True, - "makes_use_of": set(), "inspects_source": False, "manipulates_source": False, "manipulates_state": False, @@ -69,7 +67,6 @@ class Willing(Player): "memory_depth": 1, "long_run_time": False, "stochastic": True, - "makes_use_of": set(), "inspects_source": False, "manipulates_source": False, "manipulates_state": False, diff --git a/axelrod/strategies/negation.py b/axelrod/strategies/negation.py index cccf218a1..ff8cb778f 100644 --- a/axelrod/strategies/negation.py +++ b/axelrod/strategies/negation.py @@ -19,7 +19,6 @@ class Negation(Player): classifier = { "memory_depth": 1, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/oncebitten.py b/axelrod/strategies/oncebitten.py index 4703e3c70..977cfb928 100644 --- a/axelrod/strategies/oncebitten.py +++ b/axelrod/strategies/oncebitten.py @@ -20,7 +20,6 @@ class OnceBitten(Player): classifier = { "memory_depth": 12, # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -67,7 +66,6 @@ class FoolMeOnce(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -98,7 +96,6 @@ class ForgetfulFoolMeOnce(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/prober.py b/axelrod/strategies/prober.py index 96940a1fc..7b4b23fc0 100644 --- a/axelrod/strategies/prober.py +++ b/axelrod/strategies/prober.py @@ -28,7 +28,6 @@ class CollectiveStrategy(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), # Long memory - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -63,7 +62,6 @@ class Detective(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -101,7 +99,6 @@ class Prober(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), # Long memory - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -138,7 +135,6 @@ class Prober2(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), # Long memory - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -175,7 +171,6 @@ class Prober3(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), # Long memory - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -213,7 +208,6 @@ class Prober4(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -284,7 +278,6 @@ class HardProber(Player): classifier = { "stochastic": False, "memory_depth": float("inf"), # Long memory - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -322,7 +315,6 @@ class NaiveProber(Player): classifier = { "memory_depth": 1, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -374,7 +366,6 @@ class RemorsefulProber(NaiveProber): classifier = { "memory_depth": 2, # It remembers if its previous move was random "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/punisher.py b/axelrod/strategies/punisher.py index dd8145576..043dc0012 100644 --- a/axelrod/strategies/punisher.py +++ b/axelrod/strategies/punisher.py @@ -22,7 +22,6 @@ class Punisher(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -77,7 +76,6 @@ class InversePunisher(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -128,7 +126,6 @@ class LevelPunisher(Player): classifier = { "memory_depth": float("inf"), # Long Memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -161,7 +158,6 @@ class TrickyLevelPunisher(Player): classifier = { "memory_depth": float("inf"), # Long Memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/qlearner.py b/axelrod/strategies/qlearner.py index dd308feb6..f1b1c5bce 100644 --- a/axelrod/strategies/qlearner.py +++ b/axelrod/strategies/qlearner.py @@ -27,7 +27,6 @@ class RiskyQLearner(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": True, - "makes_use_of": set(["game"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/rand.py b/axelrod/strategies/rand.py index eb259e37c..1d8dcce43 100644 --- a/axelrod/strategies/rand.py +++ b/axelrod/strategies/rand.py @@ -18,7 +18,6 @@ class Random(Player): classifier = { "memory_depth": 0, # Memory-one Four-Vector = (p, p, p, p) "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/resurrection.py b/axelrod/strategies/resurrection.py index de266320a..76a61a355 100644 --- a/axelrod/strategies/resurrection.py +++ b/axelrod/strategies/resurrection.py @@ -22,7 +22,6 @@ class Resurrection(Player): classifier = { "memory_depth": 5, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -55,7 +54,6 @@ class DoubleResurrection(Player): classifier = { "memory_depth": 5, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/retaliate.py b/axelrod/strategies/retaliate.py index be4b49648..404143bc2 100644 --- a/axelrod/strategies/retaliate.py +++ b/axelrod/strategies/retaliate.py @@ -21,7 +21,6 @@ class Retaliate(Player): "memory_depth": float("inf"), # Long memory "stochastic": False, "inspects_source": False, - "makes_use_of": set(), "long_run_time": False, "manipulates_source": False, "manipulates_state": False, @@ -98,7 +97,6 @@ class LimitedRetaliate(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/revised_downing.py b/axelrod/strategies/revised_downing.py index 530905c1b..dec78e378 100644 --- a/axelrod/strategies/revised_downing.py +++ b/axelrod/strategies/revised_downing.py @@ -28,7 +28,6 @@ class RevisedDowning(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/selfsteem.py b/axelrod/strategies/selfsteem.py index 59b43657b..2ef55ce0a 100644 --- a/axelrod/strategies/selfsteem.py +++ b/axelrod/strategies/selfsteem.py @@ -30,7 +30,6 @@ class SelfSteem(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/sequence_player.py b/axelrod/strategies/sequence_player.py index d04d30830..58c7b6d3f 100644 --- a/axelrod/strategies/sequence_player.py +++ b/axelrod/strategies/sequence_player.py @@ -69,7 +69,6 @@ class ThueMorse(SequencePlayer): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -92,7 +91,6 @@ class ThueMorseInverse(ThueMorse): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/shortmem.py b/axelrod/strategies/shortmem.py index 23bf7c523..f110f56b8 100644 --- a/axelrod/strategies/shortmem.py +++ b/axelrod/strategies/shortmem.py @@ -24,7 +24,6 @@ class ShortMem(Player): classifier = { "memory_depth": float('inf'), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/stalker.py b/axelrod/strategies/stalker.py index bc533cfa3..cbba3709b 100644 --- a/axelrod/strategies/stalker.py +++ b/axelrod/strategies/stalker.py @@ -35,7 +35,6 @@ class Stalker(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(["game", "length"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/titfortat.py b/axelrod/strategies/titfortat.py index cb3b79245..bd2386a14 100644 --- a/axelrod/strategies/titfortat.py +++ b/axelrod/strategies/titfortat.py @@ -29,7 +29,6 @@ class TitForTat(Player): classifier = { "memory_depth": 1, # Four-Vector = (1.,0.,1.,0.) "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -65,7 +64,6 @@ class TitFor2Tats(Player): classifier = { "memory_depth": 2, # Long memory, memory-2 "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -90,7 +88,6 @@ class TwoTitsForTat(Player): classifier = { "memory_depth": 2, # Long memory, memory-2 "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -119,7 +116,6 @@ class DynamicTwoTitsForTat(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -156,7 +152,6 @@ class Bully(Player): classifier = { "memory_depth": 1, # Four-Vector = (0, 1, 0, 1) "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -180,7 +175,6 @@ class SneakyTitForTat(Player): classifier = { "memory_depth": float("inf"), # Long memory "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -210,7 +204,6 @@ class SuspiciousTitForTat(Player): classifier = { "memory_depth": 1, # Four-Vector = (1.,0.,1.,0.) "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -236,7 +229,6 @@ class AntiTitForTat(Player): classifier = { "memory_depth": 1, # Four-Vector = (1.,0.,1.,0.) "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -260,7 +252,6 @@ class HardTitForTat(Player): classifier = { "memory_depth": 3, # memory-three "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -292,7 +283,6 @@ class HardTitFor2Tats(Player): classifier = { "memory_depth": 3, # memory-three "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -327,7 +317,6 @@ class OmegaTFT(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -408,7 +397,6 @@ class OriginalGradual(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -476,7 +464,6 @@ class Gradual(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -526,7 +513,6 @@ class ContriteTitForTat(Player): classifier = { "memory_depth": 3, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -593,7 +579,6 @@ class AdaptiveTitForTat(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -637,7 +622,6 @@ class SpitefulTitForTat(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -679,7 +663,6 @@ class SlowTitForTwoTats2(Player): classifier = { "memory_depth": 2, "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -714,7 +697,6 @@ class Alexei(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -745,7 +727,6 @@ class EugineNier(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -782,7 +763,6 @@ class NTitsForMTats(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -840,7 +820,6 @@ class Michaelos(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": {"length"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -884,7 +863,6 @@ class RandomTitForTat(Player): classifier = { "memory_depth": 1, "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/verybad.py b/axelrod/strategies/verybad.py index 7a50b8fe5..02f07efb6 100644 --- a/axelrod/strategies/verybad.py +++ b/axelrod/strategies/verybad.py @@ -24,7 +24,6 @@ class VeryBad(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/worse_and_worse.py b/axelrod/strategies/worse_and_worse.py index cd80ca822..f428c545f 100644 --- a/axelrod/strategies/worse_and_worse.py +++ b/axelrod/strategies/worse_and_worse.py @@ -21,7 +21,6 @@ class WorseAndWorse(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -47,7 +46,6 @@ class KnowledgeableWorseAndWorse(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(["length"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -75,7 +73,6 @@ class WorseAndWorse2(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -109,7 +106,6 @@ class WorseAndWorse3(Player): classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/strategies/zero_determinant.py b/axelrod/strategies/zero_determinant.py index aaacfb130..7b849eadb 100644 --- a/axelrod/strategies/zero_determinant.py +++ b/axelrod/strategies/zero_determinant.py @@ -54,7 +54,6 @@ class LRPlayer(MemoryOnePlayer): classifier = { "memory_depth": 1, # Memory-one Four-Vector "stochastic": True, - "makes_use_of": set(["game"]), "long_run_time": False, "inspects_source": False, "manipulates_source": False, From fe3b83bb897fd7ea892c2a53c40d305cd4b6561a Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sun, 12 Apr 2020 14:35:31 -0700 Subject: [PATCH 3/8] Replace makes_use_of classifier --- axelrod/classifier.py | 15 ++- axelrod/data/all_classifiers.yml | 186 ++++++++++++++---------------- axelrod/makes_use_of.py | 18 ++- axelrod/strategies/meta.py | 43 +++++-- axelrod/strategy_transformers.py | 45 ++++++-- test_outputs/classifier_test.yaml | 4 + 6 files changed, 179 insertions(+), 132 deletions(-) create mode 100644 test_outputs/classifier_test.yaml diff --git a/axelrod/classifier.py b/axelrod/classifier.py index a88dbe39e..a002c8fc9 100644 --- a/axelrod/classifier.py +++ b/axelrod/classifier.py @@ -14,6 +14,7 @@ import warnings import yaml +from axelrod.makes_use_of import makes_use_of from axelrod.player import Player ALL_CLASSIFIERS_PATH = "data/all_classifiers.yml" @@ -59,12 +60,18 @@ def classify_player(self, player: Type[Player]) -> T: stochastic = Classifier[bool]("stochastic", lambda _: False) -memory_depth = Classifier[Union[float, int]]("memory_depth", lambda _: float("inf")) -makes_use_of = Classifier[Optional[Set[Text]]]("makes_use_of", lambda _: None) +memory_depth = Classifier[Union[float, int]]( + "memory_depth", lambda _: float("inf") +) +makes_use_of = Classifier[Optional[Set[Text]]]("makes_use_of", makes_use_of) long_run_time = Classifier[bool]("long_run_time", lambda _: False) inspects_source = Classifier[Optional[bool]]("inspects_source", lambda _: None) -manipulates_source = Classifier[Optional[bool]]("manipulates_source", lambda _: None) -manipulates_state = Classifier[Optional[bool]]("manipulates_state", lambda _: None) +manipulates_source = Classifier[Optional[bool]]( + "manipulates_source", lambda _: None +) +manipulates_state = Classifier[Optional[bool]]( + "manipulates_state", lambda _: None +) # Should list all known classifiers. all_classifiers = [ diff --git a/axelrod/data/all_classifiers.yml b/axelrod/data/all_classifiers.yml index 32d004187..b9f2de9d9 100644 --- a/axelrod/data/all_classifiers.yml +++ b/axelrod/data/all_classifiers.yml @@ -1,7 +1,7 @@ $\phi$: inspects_source: false long_run_time: false - makes_use_of: &id001 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -9,7 +9,7 @@ $\phi$: $\pi$: inspects_source: false long_run_time: false - makes_use_of: *id001 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -17,7 +17,7 @@ $\pi$: $e$: inspects_source: false long_run_time: false - makes_use_of: *id001 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -41,8 +41,7 @@ AON2: Adaptive: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -74,7 +73,7 @@ Adaptive Tit For Tat: AdaptorBrief: inspects_source: false long_run_time: false - makes_use_of: &id002 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -82,7 +81,7 @@ AdaptorBrief: AdaptorLong: inspects_source: false long_run_time: false - makes_use_of: *id002 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -147,8 +146,7 @@ Appeaser: Arrogant QLearner: inspects_source: false long_run_time: false - makes_use_of: &id003 !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -189,8 +187,7 @@ Bully: Bush Mosteller: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -206,7 +203,7 @@ Calculator: Cautious QLearner: inspects_source: false long_run_time: false - makes_use_of: *id003 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -246,7 +243,7 @@ Cooperator Hunter: Cycle Hunter: inspects_source: false long_run_time: false - makes_use_of: &id005 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -254,7 +251,7 @@ Cycle Hunter: Cycler CCCCCD: inspects_source: false long_run_time: false - makes_use_of: &id004 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 5 @@ -262,7 +259,7 @@ Cycler CCCCCD: Cycler CCCD: inspects_source: false long_run_time: false - makes_use_of: *id004 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 3 @@ -270,7 +267,7 @@ Cycler CCCD: Cycler CCCDCD: inspects_source: false long_run_time: false - makes_use_of: *id004 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 5 @@ -278,7 +275,7 @@ Cycler CCCDCD: Cycler CCD: inspects_source: false long_run_time: false - makes_use_of: *id004 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 2 @@ -286,7 +283,7 @@ Cycler CCD: Cycler DC: inspects_source: false long_run_time: false - makes_use_of: *id004 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -294,7 +291,7 @@ Cycler DC: Cycler DDC: inspects_source: false long_run_time: false - makes_use_of: *id004 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 2 @@ -408,7 +405,7 @@ EugineNier: Eventual Cycle Hunter: inspects_source: false long_run_time: false - makes_use_of: *id005 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -416,7 +413,7 @@ Eventual Cycle Hunter: Evolved ANN: inspects_source: false long_run_time: false - makes_use_of: &id006 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -424,7 +421,7 @@ Evolved ANN: Evolved ANN 5: inspects_source: false long_run_time: false - makes_use_of: *id006 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -432,7 +429,7 @@ Evolved ANN 5: Evolved ANN 5 Noise 05: inspects_source: false long_run_time: false - makes_use_of: *id006 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -472,7 +469,7 @@ Evolved HMM 5: EvolvedLookerUp1_1_1: inspects_source: false long_run_time: false - makes_use_of: &id007 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -480,7 +477,7 @@ EvolvedLookerUp1_1_1: EvolvedLookerUp2_2_2: inspects_source: false long_run_time: false - makes_use_of: *id007 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -488,7 +485,7 @@ EvolvedLookerUp2_2_2: Firm But Fair: inspects_source: false long_run_time: false - makes_use_of: &id008 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -512,8 +509,7 @@ First by Davis: First by Downing: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -545,7 +541,7 @@ First by Grofman: First by Joss: inspects_source: false long_run_time: false - makes_use_of: *id008 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -579,7 +575,6 @@ First by Tideman and Chieruzzi: inspects_source: false long_run_time: false makes_use_of: !!set - game: null length: null manipulates_source: false manipulates_state: false @@ -652,8 +647,7 @@ Fortress4: GTFT: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -693,7 +687,7 @@ General Soft Grudger: Go By Majority: inspects_source: false long_run_time: false - makes_use_of: &id009 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -701,7 +695,7 @@ Go By Majority: Go By Majority 10: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 10 @@ -709,7 +703,7 @@ Go By Majority 10: Go By Majority 20: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 20 @@ -717,7 +711,7 @@ Go By Majority 20: Go By Majority 40: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 40 @@ -725,7 +719,7 @@ Go By Majority 40: Go By Majority 5: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 5 @@ -781,7 +775,7 @@ Handshake: Hard Go By Majority: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -789,7 +783,7 @@ Hard Go By Majority: Hard Go By Majority 10: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 10 @@ -797,7 +791,7 @@ Hard Go By Majority 10: Hard Go By Majority 20: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 20 @@ -805,7 +799,7 @@ Hard Go By Majority 20: Hard Go By Majority 40: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 40 @@ -813,7 +807,7 @@ Hard Go By Majority 40: Hard Go By Majority 5: inspects_source: false long_run_time: false - makes_use_of: *id009 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 5 @@ -845,7 +839,7 @@ Hard Tit For Tat: Hesitant QLearner: inspects_source: false long_run_time: false - makes_use_of: *id003 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -877,8 +871,7 @@ Inverse Punisher: Knowledgeable Worse and Worse: inspects_source: false long_run_time: false - makes_use_of: !!set - length: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -894,7 +887,7 @@ Level Punisher: Limited Retaliate: inspects_source: false long_run_time: false - makes_use_of: &id010 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -902,7 +895,7 @@ Limited Retaliate: Limited Retaliate 2: inspects_source: false long_run_time: false - makes_use_of: *id010 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -910,7 +903,7 @@ Limited Retaliate 2: Limited Retaliate 3: inspects_source: false long_run_time: false - makes_use_of: *id010 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -958,7 +951,7 @@ Meta Hunter Aggressive: Meta Majority: inspects_source: false long_run_time: true - makes_use_of: &id011 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -966,7 +959,7 @@ Meta Majority: Meta Majority Finite Memory: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -974,7 +967,7 @@ Meta Majority Finite Memory: Meta Majority Long Memory: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -982,7 +975,7 @@ Meta Majority Long Memory: Meta Majority Memory One: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -990,7 +983,7 @@ Meta Majority Memory One: Meta Minority: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1006,7 +999,7 @@ Meta Mixer: Meta Winner: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1014,7 +1007,7 @@ Meta Winner: Meta Winner Deterministic: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1022,7 +1015,7 @@ Meta Winner Deterministic: Meta Winner Ensemble: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1030,7 +1023,7 @@ Meta Winner Ensemble: Meta Winner Finite Memory: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1038,7 +1031,7 @@ Meta Winner Finite Memory: Meta Winner Long Memory: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1046,7 +1039,7 @@ Meta Winner Long Memory: Meta Winner Memory One: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1054,7 +1047,7 @@ Meta Winner Memory One: Meta Winner Stochastic: inspects_source: false long_run_time: true - makes_use_of: *id011 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1119,7 +1112,7 @@ N Tit(s) For M Tat(s): NMWE Deterministic: inspects_source: false long_run_time: true - makes_use_of: &id012 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1127,7 +1120,7 @@ NMWE Deterministic: NMWE Finite Memory: inspects_source: false long_run_time: true - makes_use_of: *id012 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1135,7 +1128,7 @@ NMWE Finite Memory: NMWE Long Memory: inspects_source: false long_run_time: true - makes_use_of: *id012 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1143,7 +1136,7 @@ NMWE Long Memory: NMWE Memory One: inspects_source: false long_run_time: true - makes_use_of: *id012 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1151,7 +1144,7 @@ NMWE Memory One: NMWE Stochastic: inspects_source: false long_run_time: true - makes_use_of: *id012 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1191,7 +1184,7 @@ Nice Meta Winner: Nice Meta Winner Ensemble: inspects_source: false long_run_time: true - makes_use_of: *id012 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1223,7 +1216,7 @@ Opposite Grudger: PSO Gambler 1_1_1: inspects_source: false long_run_time: false - makes_use_of: &id013 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1231,7 +1224,7 @@ PSO Gambler 1_1_1: PSO Gambler 2_2_2: inspects_source: false long_run_time: false - makes_use_of: *id013 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1239,7 +1232,7 @@ PSO Gambler 2_2_2: PSO Gambler 2_2_2 Noise 05: inspects_source: false long_run_time: false - makes_use_of: *id013 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1247,7 +1240,7 @@ PSO Gambler 2_2_2 Noise 05: PSO Gambler Mem1: inspects_source: false long_run_time: false - makes_use_of: *id013 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1367,7 +1360,7 @@ Resurrection: Retaliate: inspects_source: false long_run_time: false - makes_use_of: &id014 !!set {} + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1375,7 +1368,7 @@ Retaliate: Retaliate 2: inspects_source: false long_run_time: false - makes_use_of: *id014 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1383,7 +1376,7 @@ Retaliate 2: Retaliate 3: inspects_source: false long_run_time: false - makes_use_of: *id014 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1407,7 +1400,7 @@ Ripoff: Risky QLearner: inspects_source: false long_run_time: false - makes_use_of: *id003 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1487,8 +1480,7 @@ Second by Gladstein: Second by GraaskampKatzen: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1544,11 +1536,7 @@ Second by RichardHufford: Second by Rowsam: inspects_source: false long_run_time: false - makes_use_of: !!set - a: null - e: null - g: null - m: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1564,8 +1552,7 @@ Second by Tester: Second by Tideman and Chieruzzi: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1573,8 +1560,7 @@ Second by Tideman and Chieruzzi: Second by Tranquilizer: inspects_source: false long_run_time: false - makes_use_of: !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1654,7 +1640,7 @@ Soft Grudger: Soft Joss: inspects_source: false long_run_time: false - makes_use_of: *id008 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1687,7 +1673,6 @@ Stalker: inspects_source: false long_run_time: false makes_use_of: !!set - game: null length: null manipulates_source: false manipulates_state: false @@ -1696,7 +1681,7 @@ Stalker: Stochastic Cooperator: inspects_source: false long_run_time: false - makes_use_of: *id008 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1704,7 +1689,7 @@ Stochastic Cooperator: Stochastic WSLS: inspects_source: false long_run_time: false - makes_use_of: *id008 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1864,7 +1849,7 @@ Win-Stay Lose-Shift: Winner12: inspects_source: false long_run_time: false - makes_use_of: *id007 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1872,7 +1857,7 @@ Winner12: Winner21: inspects_source: false long_run_time: false - makes_use_of: *id007 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1904,8 +1889,7 @@ Worse and Worse 3: ZD-Extort-2: inspects_source: false long_run_time: false - makes_use_of: &id015 !!set - game: null + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1913,7 +1897,7 @@ ZD-Extort-2: ZD-Extort-2 v2: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1921,7 +1905,7 @@ ZD-Extort-2 v2: ZD-Extort-4: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1929,7 +1913,7 @@ ZD-Extort-4: ZD-Extort3: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1937,7 +1921,7 @@ ZD-Extort3: ZD-Extortion: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1945,7 +1929,7 @@ ZD-Extortion: ZD-GEN-2: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1953,7 +1937,7 @@ ZD-GEN-2: ZD-GTFT-2: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1969,7 +1953,7 @@ ZD-Mem2: ZD-Mischief: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1977,7 +1961,7 @@ ZD-Mischief: ZD-SET-2: inspects_source: false long_run_time: false - makes_use_of: *id015 + makes_use_of: !!set {} manipulates_source: false manipulates_state: false memory_depth: 1 diff --git a/axelrod/makes_use_of.py b/axelrod/makes_use_of.py index d55fe3f9a..6804f791e 100644 --- a/axelrod/makes_use_of.py +++ b/axelrod/makes_use_of.py @@ -1,18 +1,24 @@ import inspect import re -from typing import Set, Text, Type +from typing import Callable, Set, Text, Type from axelrod.player import Player +def method_makes_use_of(method: Callable) -> Set[Text]: + result = set() + method_code = inspect.getsource(method) + attr_string = r".match_attributes\[\"(\w+)\"\]" + all_attrs = re.findall(attr_string, method_code) + for attr in all_attrs: + result.add(attr) + return result + + def makes_use_of(player: Type[Player]) -> Set[Text]: result = set() for method in inspect.getmembers(player, inspect.ismethod): if method[0] == "__init__": continue - method_code = inspect.getsource(method[1]) - attr_string = r"self.match_attributes\[\"(\w+)\"\]" - all_attrs = re.findall(attr_string, method_code) - for attr in all_attrs: - result.add(attr) + result.update(method_makes_use_of(method[1])) return result diff --git a/axelrod/strategies/meta.py b/axelrod/strategies/meta.py index f71198aae..f5c53e7a3 100644 --- a/axelrod/strategies/meta.py +++ b/axelrod/strategies/meta.py @@ -20,7 +20,9 @@ ) # Needs to be computed manually to prevent circular dependency -ordinary_strategies = [s for s in all_strategies if Classifiers.obey_axelrod(s())] +ordinary_strategies = [ + s for s in all_strategies if Classifiers.obey_axelrod(s()) +] C, D = Action.C, Action.D @@ -70,8 +72,11 @@ def __init__(self, team=None): ]: self.classifier[key] = any(map(Classifiers[key], self.team)) + self.classifier["makes_use_of"] = set() for t in self.team: - self.classifier["makes_use_of"].update(Classifiers["makes_use_of"](t)) + new_uses = Classifiers["makes_use_of"](t) + if new_uses: + self.classifier["makes_use_of"].update(new_uses) self._last_results = None @@ -329,7 +334,11 @@ class MetaMajorityMemoryOne(MetaMajority): name = "Meta Majority Memory One" def __init__(self): - team = [s for s in ordinary_strategies if Classifiers["memory_depth"](s()) <= 1] + team = [ + s + for s in ordinary_strategies + if Classifiers["memory_depth"](s()) <= 1 + ] super().__init__(team=team) self.classifier["long_run_time"] = False @@ -383,7 +392,11 @@ class MetaWinnerMemoryOne(MetaWinner): name = "Meta Winner Memory One" def __init__(self): - team = [s for s in ordinary_strategies if Classifiers["memory_depth"](s()) <= 1] + team = [ + s + for s in ordinary_strategies + if Classifiers["memory_depth"](s()) <= 1 + ] super().__init__(team=team) self.classifier["long_run_time"] = False @@ -437,7 +450,9 @@ class MetaWinnerDeterministic(MetaWinner): name = "Meta Winner Deterministic" def __init__(self): - team = [s for s in ordinary_strategies if not Classifiers["stochastic"](s())] + team = [ + s for s in ordinary_strategies if not Classifiers["stochastic"](s()) + ] super().__init__(team=team) self.classifier["stochastic"] = False @@ -453,7 +468,9 @@ class MetaWinnerStochastic(MetaWinner): name = "Meta Winner Stochastic" def __init__(self): - team = [s for s in ordinary_strategies if Classifiers["stochastic"](s())] + team = [ + s for s in ordinary_strategies if Classifiers["stochastic"](s()) + ] super().__init__(team=team) @@ -508,7 +525,9 @@ class NMWEDeterministic(NiceMetaWinnerEnsemble): name = "NMWE Deterministic" def __init__(self): - team = [s for s in ordinary_strategies if not Classifiers["stochastic"](s())] + team = [ + s for s in ordinary_strategies if not Classifiers["stochastic"](s()) + ] super().__init__(team=team) self.classifier["stochastic"] = True @@ -524,7 +543,9 @@ class NMWEStochastic(NiceMetaWinnerEnsemble): name = "NMWE Stochastic" def __init__(self): - team = [s for s in ordinary_strategies if Classifiers["stochastic"](s())] + team = [ + s for s in ordinary_strategies if Classifiers["stochastic"](s()) + ] super().__init__(team=team) @@ -577,7 +598,11 @@ class NMWEMemoryOne(NiceMetaWinnerEnsemble): name = "NMWE Memory One" def __init__(self): - team = [s for s in ordinary_strategies if Classifiers["memory_depth"](s()) <= 1] + team = [ + s + for s in ordinary_strategies + if Classifiers["memory_depth"](s()) <= 1 + ] super().__init__(team=team) self.classifier["long_run_time"] = False diff --git a/axelrod/strategy_transformers.py b/axelrod/strategy_transformers.py index 6d50d77c2..34161ee3b 100644 --- a/axelrod/strategy_transformers.py +++ b/axelrod/strategy_transformers.py @@ -16,6 +16,7 @@ from axelrod.strategies.sequence_player import SequencePlayer from .action import Action +from .makes_use_of import method_makes_use_of from .player import Player from .random_ import random_choice @@ -27,7 +28,9 @@ # Alternator. -def StrategyTransformerFactory(strategy_wrapper, name_prefix=None, reclassifier=None): +def StrategyTransformerFactory( + strategy_wrapper, name_prefix=None, reclassifier=None +): """Modify an existing strategy dynamically by wrapping the strategy method with the argument `strategy_wrapper`. @@ -130,6 +133,11 @@ def strategy(self, opponent): classifier = reclassifier(original_classifier, *args, **kwargs) else: classifier = original_classifier + strategy_wrapper_uses = method_makes_use_of(strategy_wrapper) + if "makes_use_of" in classifier: + classifier["makes_use_of"].update(strategy_wrapper_uses) + elif strategy_wrapper_uses: + classifier["makes_use_of"] = strategy_wrapper_uses # Define the new __repr__ method to add the wrapper arguments # at the end of the name @@ -232,7 +240,11 @@ class DecoratorReBuilder(object): """ def __call__( - self, factory_args: tuple, args: tuple, kwargs: dict, instance_name_prefix: str + self, + factory_args: tuple, + args: tuple, + kwargs: dict, + instance_name_prefix: str, ) -> Any: decorator_class = StrategyTransformerFactory(*factory_args) @@ -246,7 +258,9 @@ class StrategyReBuilder(object): that could not normally be pickled. """ - def __call__(self, decorators: list, import_name: str, module_name: str) -> Player: + def __call__( + self, decorators: list, import_name: str, module_name: str + ) -> Player: module_ = import_module(module_name) import_class = getattr(module_, import_name) @@ -275,7 +289,9 @@ def __call__(self, PlayerClass): return Composition() -def generic_strategy_wrapper(player, opponent, proposed_action, *args, **kwargs): +def generic_strategy_wrapper( + player, opponent, proposed_action, *args, **kwargs +): """ Strategy wrapper functions should be of the following form. @@ -307,7 +323,9 @@ def flip_wrapper(player, opponent, action): return action.flip() -FlipTransformer = StrategyTransformerFactory(flip_wrapper, name_prefix="Flipped") +FlipTransformer = StrategyTransformerFactory( + flip_wrapper, name_prefix="Flipped" +) def dual_wrapper(player, opponent: Player, proposed_action: Action) -> Action: @@ -377,7 +395,9 @@ def forgiver_reclassifier(original_classifier, p): ForgiverTransformer = StrategyTransformerFactory( - forgiver_wrapper, name_prefix="Forgiving", reclassifier=forgiver_reclassifier + forgiver_wrapper, + name_prefix="Forgiving", + reclassifier=forgiver_reclassifier, ) @@ -442,7 +462,6 @@ def final_sequence(player, opponent, action, seq): def final_reclassifier(original_classifier, seq): """Reclassify the strategy""" - original_classifier["makes_use_of"].update(["length"]) original_classifier["memory_depth"] = max( len(seq), original_classifier["memory_depth"] ) @@ -495,14 +514,18 @@ def grudge_wrapper(player, opponent, action, grudges): return action -GrudgeTransformer = StrategyTransformerFactory(grudge_wrapper, name_prefix="Grudging") +GrudgeTransformer = StrategyTransformerFactory( + grudge_wrapper, name_prefix="Grudging" +) def apology_wrapper(player, opponent, action, myseq, opseq): length = len(myseq) if len(player.history) < length: return action - if (myseq == player.history[-length:]) and (opseq == opponent.history[-length:]): + if (myseq == player.history[-length:]) and ( + opseq == opponent.history[-length:] + ): return C return action @@ -535,9 +558,7 @@ def mixed_wrapper(player, opponent, action, probability, m_player): probability = [probability] # If a probability distribution, players is passed - if isinstance(probability, Iterable) and isinstance( - m_player, Iterable - ): + if isinstance(probability, Iterable) and isinstance(m_player, Iterable): mutate_prob = sum(probability) # Prob of mutation if mutate_prob > 0: # Distribution of choice of mutation: diff --git a/test_outputs/classifier_test.yaml b/test_outputs/classifier_test.yaml new file mode 100644 index 000000000..106f7511c --- /dev/null +++ b/test_outputs/classifier_test.yaml @@ -0,0 +1,4 @@ +Cooperator: + name: Cooperator +Defector: + name: Defector From 0669a19573ea6a3d6d3ea7d8aec3400b48c5fbb2 Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sun, 14 Jun 2020 19:45:14 -0700 Subject: [PATCH 4/8] Erase makes_use_of in mindreader --- axelrod/strategies/mindreader.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/axelrod/strategies/mindreader.py b/axelrod/strategies/mindreader.py index 3d34c0f3e..c1f078e89 100644 --- a/axelrod/strategies/mindreader.py +++ b/axelrod/strategies/mindreader.py @@ -23,7 +23,6 @@ class MindReader(Player): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": False, @@ -61,7 +60,6 @@ class ProtectedMindReader(MindReader): classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": True, # Finds out what opponent will do "manipulates_source": True, # Stops opponent's strategy From 6cd3fd84b43f3d56ac2760c41c41de5834bbb42a Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sat, 4 Jul 2020 20:17:48 -0700 Subject: [PATCH 5/8] Fix makes_use_of --- .gitignore | 1 + axelrod/classifier.py | 10 +- axelrod/data/all_classifiers.yml | 105 ++++++++++++------ axelrod/makes_use_of.py | 15 ++- axelrod/strategy_transformers.py | 11 +- .../tests/strategies/test_axelrod_second.py | 4 +- axelrod/tests/strategies/test_darwin.py | 2 +- axelrod/tests/strategies/test_player.py | 1 - 8 files changed, 101 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 0c3f3de6d..5ae74f480 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,7 @@ docker-compose.yml # Mypy files .mypy_cache/ +test_outputs/classifier_test.yaml test_outputs/stochastic_tournament_0.csv test_outputs/stochastic_tournament_1.csv test_outputs/test_fingerprint.csv diff --git a/axelrod/classifier.py b/axelrod/classifier.py index a002c8fc9..9145efd11 100644 --- a/axelrod/classifier.py +++ b/axelrod/classifier.py @@ -84,6 +84,8 @@ def classify_player(self, player: Type[Player]) -> T: manipulates_state, ] +all_classifiers_map = {c.name: c.classify_player for c in all_classifiers} + def rebuild_classifier_table( classifiers: List[Classifier], @@ -216,7 +218,13 @@ def try_lookup() -> Any: return player.classifier[key] # Try to find the name in the all_player_dicts, read from disk. - return try_lookup() + lookup = try_lookup() + if lookup is not None: + return lookup + + # If we can't find it, then return a function that calculates fresh. + global all_classifiers_map + return all_classifiers_map[key](player) return classify_player_for_this_classifier diff --git a/axelrod/data/all_classifiers.yml b/axelrod/data/all_classifiers.yml index 4ef726665..f028f5ab4 100644 --- a/axelrod/data/all_classifiers.yml +++ b/axelrod/data/all_classifiers.yml @@ -41,7 +41,8 @@ AON2: Adaptive: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -146,7 +147,8 @@ Appeaser: Arrogant QLearner: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -187,7 +189,8 @@ Bully: Bush Mosteller: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -203,7 +206,8 @@ Calculator: Cautious QLearner: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -307,7 +311,8 @@ DBS: Darwin: inspects_source: true long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: true memory_depth: .inf @@ -509,7 +514,8 @@ First by Davis: First by Downing: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -575,6 +581,7 @@ First by Tideman and Chieruzzi: inspects_source: false long_run_time: false makes_use_of: !!set + game: null length: null manipulates_source: false manipulates_state: false @@ -647,7 +654,8 @@ Fortress4: GTFT: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -839,7 +847,8 @@ Hard Tit For Tat: Hesitant QLearner: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -871,7 +880,8 @@ Inverse Punisher: Knowledgeable Worse and Worse: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + length: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -999,7 +1009,8 @@ Meta Mixer: Meta Winner: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1007,7 +1018,8 @@ Meta Winner: Meta Winner Deterministic: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1015,7 +1027,8 @@ Meta Winner Deterministic: Meta Winner Ensemble: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1023,7 +1036,8 @@ Meta Winner Ensemble: Meta Winner Finite Memory: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1031,7 +1045,8 @@ Meta Winner Finite Memory: Meta Winner Long Memory: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1039,7 +1054,8 @@ Meta Winner Long Memory: Meta Winner Memory One: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1047,7 +1063,8 @@ Meta Winner Memory One: Meta Winner Stochastic: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1113,7 +1130,8 @@ N Tit(s) For M Tat(s): NMWE Deterministic: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: &id001 !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1121,7 +1139,7 @@ NMWE Deterministic: NMWE Finite Memory: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: *id001 manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1129,7 +1147,7 @@ NMWE Finite Memory: NMWE Long Memory: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: *id001 manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1137,7 +1155,7 @@ NMWE Long Memory: NMWE Memory One: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: *id001 manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1145,7 +1163,7 @@ NMWE Memory One: NMWE Stochastic: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: *id001 manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1177,7 +1195,8 @@ Nice Average Copier: Nice Meta Winner: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1185,7 +1204,7 @@ Nice Meta Winner: Nice Meta Winner Ensemble: inspects_source: false long_run_time: true - makes_use_of: !!set {} + makes_use_of: *id001 manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1410,7 +1429,8 @@ Ripoff: Risky QLearner: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1490,7 +1510,8 @@ Second by Gladstein: Second by GraaskampKatzen: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1546,7 +1567,8 @@ Second by RichardHufford: Second by Rowsam: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1562,7 +1584,8 @@ Second by Tester: Second by Tideman and Chieruzzi: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: .inf @@ -1683,6 +1706,7 @@ Stalker: inspects_source: false long_run_time: false makes_use_of: !!set + game: null length: null manipulates_source: false manipulates_state: false @@ -1899,7 +1923,8 @@ Worse and Worse 3: ZD-Extort-2: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1907,7 +1932,8 @@ ZD-Extort-2: ZD-Extort-2 v2: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1915,7 +1941,8 @@ ZD-Extort-2 v2: ZD-Extort-4: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1923,7 +1950,8 @@ ZD-Extort-4: ZD-Extort3: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1931,7 +1959,8 @@ ZD-Extort3: ZD-Extortion: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1939,7 +1968,8 @@ ZD-Extortion: ZD-GEN-2: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1947,7 +1977,8 @@ ZD-GEN-2: ZD-GTFT-2: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1963,7 +1994,8 @@ ZD-Mem2: ZD-Mischief: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 @@ -1971,7 +2003,8 @@ ZD-Mischief: ZD-SET-2: inspects_source: false long_run_time: false - makes_use_of: !!set {} + makes_use_of: !!set + game: null manipulates_source: false manipulates_state: false memory_depth: 1 diff --git a/axelrod/makes_use_of.py b/axelrod/makes_use_of.py index 6804f791e..2ada93375 100644 --- a/axelrod/makes_use_of.py +++ b/axelrod/makes_use_of.py @@ -1,6 +1,6 @@ import inspect import re -from typing import Callable, Set, Text, Type +from typing import Callable, Set, Text, Type, Union from axelrod.player import Player @@ -16,9 +16,22 @@ def method_makes_use_of(method: Callable) -> Set[Text]: def makes_use_of(player: Type[Player]) -> Set[Text]: + if not isinstance(player, Player): + player = player() + result = set() for method in inspect.getmembers(player, inspect.ismethod): if method[0] == "__init__": continue result.update(method_makes_use_of(method[1])) return result + + +# def makes_use_of_variant( +# player_or_method: Union[Callable, Type[Player]], verbose=False +# ) -> Set[Text]: +# """A version of makes_use_of that works on functions or player classes.""" +# try: +# return method_makes_use_of(player_or_method) +# except: +# return makes_use_of(player_or_method) diff --git a/axelrod/strategy_transformers.py b/axelrod/strategy_transformers.py index 34161ee3b..4f18ab679 100644 --- a/axelrod/strategy_transformers.py +++ b/axelrod/strategy_transformers.py @@ -16,7 +16,7 @@ from axelrod.strategies.sequence_player import SequencePlayer from .action import Action -from .makes_use_of import method_makes_use_of +from .makes_use_of import * from .player import Player from .random_ import random_choice @@ -133,11 +133,10 @@ def strategy(self, opponent): classifier = reclassifier(original_classifier, *args, **kwargs) else: classifier = original_classifier - strategy_wrapper_uses = method_makes_use_of(strategy_wrapper) - if "makes_use_of" in classifier: - classifier["makes_use_of"].update(strategy_wrapper_uses) - elif strategy_wrapper_uses: - classifier["makes_use_of"] = strategy_wrapper_uses + classifier_makes_use_of = makes_use_of(PlayerClass) + classifier_makes_use_of.update( + method_makes_use_of(strategy_wrapper)) + classifier["makes_use_of"] = classifier_makes_use_of # Define the new __repr__ method to add the wrapper arguments # at the end of the name diff --git a/axelrod/tests/strategies/test_axelrod_second.py b/axelrod/tests/strategies/test_axelrod_second.py index 7c9122d8d..bb5df3d8d 100644 --- a/axelrod/tests/strategies/test_axelrod_second.py +++ b/axelrod/tests/strategies/test_axelrod_second.py @@ -165,7 +165,7 @@ class TestTranquilizer(TestPlayer): expected_classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": {"game"}, + "makes_use_of": set(), "long_run_time": False, "inspects_source": False, "manipulates_source": False, @@ -1823,7 +1823,7 @@ class TestRowsam(TestPlayer): expected_classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set("game"), + "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": False, "manipulates_source": False, diff --git a/axelrod/tests/strategies/test_darwin.py b/axelrod/tests/strategies/test_darwin.py index 8aa0b6391..50c0c4f2b 100644 --- a/axelrod/tests/strategies/test_darwin.py +++ b/axelrod/tests/strategies/test_darwin.py @@ -14,7 +14,7 @@ class TestDarwin(TestPlayer): expected_classifier = { "memory_depth": float("inf"), "stochastic": False, - "makes_use_of": set(), + "makes_use_of": {"game"}, "long_run_time": False, "inspects_source": True, "manipulates_source": False, diff --git a/axelrod/tests/strategies/test_player.py b/axelrod/tests/strategies/test_player.py index 2b4dd33c4..e9fe5ee44 100644 --- a/axelrod/tests/strategies/test_player.py +++ b/axelrod/tests/strategies/test_player.py @@ -637,7 +637,6 @@ def classifier_test(self, expected_class_classifier=None): ), ) - class TestMatch(unittest.TestCase): """Test class for heads up play between two given players. Plays an axelrod match between the two players.""" From e3bfc46a62ac1fc56ac6f179384536f6e89bd57c Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sat, 4 Jul 2020 22:48:45 -0700 Subject: [PATCH 6/8] Fix remaining tests --- axelrod/makes_use_of.py | 30 ++++++++++++---------- axelrod/strategy_transformers.py | 2 +- axelrod/tests/strategies/test_human.py | 2 +- axelrod/tests/strategies/test_memoryone.py | 3 --- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/axelrod/makes_use_of.py b/axelrod/makes_use_of.py index 2ada93375..41356123c 100644 --- a/axelrod/makes_use_of.py +++ b/axelrod/makes_use_of.py @@ -15,23 +15,27 @@ def method_makes_use_of(method: Callable) -> Set[Text]: return result -def makes_use_of(player: Type[Player]) -> Set[Text]: - if not isinstance(player, Player): - player = player() - +def class_makes_use_of(cls) -> Set[Text]: result = set() - for method in inspect.getmembers(player, inspect.ismethod): + for method in inspect.getmembers(cls, inspect.ismethod): if method[0] == "__init__": continue result.update(method_makes_use_of(method[1])) return result -# def makes_use_of_variant( -# player_or_method: Union[Callable, Type[Player]], verbose=False -# ) -> Set[Text]: -# """A version of makes_use_of that works on functions or player classes.""" -# try: -# return method_makes_use_of(player_or_method) -# except: -# return makes_use_of(player_or_method) +def makes_use_of(player: Type[Player]) -> Set[Text]: + if not isinstance(player, Player): + player = player() + + return class_makes_use_of(player) + + +def makes_use_of_variant( + player_or_method: Union[Callable, Type[Player]], verbose=False +) -> Set[Text]: + """A version of makes_use_of that works on functions or player classes.""" + try: + return method_makes_use_of(player_or_method) + except: + return class_makes_use_of(player_or_method) diff --git a/axelrod/strategy_transformers.py b/axelrod/strategy_transformers.py index fdacb43a6..a870797ea 100644 --- a/axelrod/strategy_transformers.py +++ b/axelrod/strategy_transformers.py @@ -135,7 +135,7 @@ def strategy(self, opponent): classifier = original_classifier classifier_makes_use_of = makes_use_of(PlayerClass) classifier_makes_use_of.update( - method_makes_use_of(strategy_wrapper)) + makes_use_of_variant(strategy_wrapper)) classifier["makes_use_of"] = classifier_makes_use_of # Define the new __repr__ method to add the wrapper arguments diff --git a/axelrod/tests/strategies/test_human.py b/axelrod/tests/strategies/test_human.py index 8b5c5e383..e0e2ca811 100644 --- a/axelrod/tests/strategies/test_human.py +++ b/axelrod/tests/strategies/test_human.py @@ -37,7 +37,7 @@ class TestHumanClass(TestPlayer): expected_classifier = { "memory_depth": float("inf"), "stochastic": True, - "makes_use_of": set(["length", "game"]), + "makes_use_of": set(), "long_run_time": True, "inspects_source": True, "manipulates_source": False, diff --git a/axelrod/tests/strategies/test_memoryone.py b/axelrod/tests/strategies/test_memoryone.py index 5b8c5f05c..a2c8e879f 100644 --- a/axelrod/tests/strategies/test_memoryone.py +++ b/axelrod/tests/strategies/test_memoryone.py @@ -24,9 +24,6 @@ class TestWinStayLoseShift(TestPlayer): "manipulates_state": False, } - def test_class_classification(self): - self.assertEqual(self.player.classifier, self.expected_classifier) - def test_strategy(self): # Check that switches if does not get best payoff. actions = [(C, C), (C, D), (D, C), (D, D), (C, C)] From 1bc997829ed49ffc0947380aefb545c43762f4de Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sun, 5 Jul 2020 00:30:19 -0700 Subject: [PATCH 7/8] Update documents for makes_use_of now auto-calculated --- docs/tutorials/advanced/classification_of_strategies.rst | 1 - .../contributing/strategy/classifying_the_new_strategy.rst | 1 - 2 files changed, 2 deletions(-) diff --git a/docs/tutorials/advanced/classification_of_strategies.rst b/docs/tutorials/advanced/classification_of_strategies.rst index 984607f7e..0702eeac7 100644 --- a/docs/tutorials/advanced/classification_of_strategies.rst +++ b/docs/tutorials/advanced/classification_of_strategies.rst @@ -12,7 +12,6 @@ Here is the :code:`classifier` for the :code:`Cooperator` strategy:: >>> import axelrod as axl >>> expected_dictionary = { ... 'manipulates_state': False, - ... 'makes_use_of': set([]), ... 'long_run_time': False, ... 'stochastic': False, ... 'manipulates_source': False, diff --git a/docs/tutorials/contributing/strategy/classifying_the_new_strategy.rst b/docs/tutorials/contributing/strategy/classifying_the_new_strategy.rst index 368705e48..70f5b83e1 100644 --- a/docs/tutorials/contributing/strategy/classifying_the_new_strategy.rst +++ b/docs/tutorials/contributing/strategy/classifying_the_new_strategy.rst @@ -15,7 +15,6 @@ Let us take a look at the dimensions available by looking at :code:`TitForTat`:: ... print(key) inspects_source long_run_time - makes_use_of manipulates_source manipulates_state memory_depth From 012af145d436a9652a6eaa97a58d499e3623860c Mon Sep 17 00:00:00 2001 From: gaffneytj Date: Sun, 5 Jul 2020 13:52:59 -0700 Subject: [PATCH 8/8] Add explicit type to FSM classifier --- axelrod/strategies/finite_state_machines.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/finite_state_machines.py b/axelrod/strategies/finite_state_machines.py index 50faa3e07..36c28b88a 100644 --- a/axelrod/strategies/finite_state_machines.py +++ b/axelrod/strategies/finite_state_machines.py @@ -1,6 +1,6 @@ import itertools from random import randrange -from typing import Any, List, Sequence, Tuple, Union +from typing import Any, Dict, List, Sequence, Text, Tuple, Union import numpy.random as random from axelrod.action import Action @@ -102,7 +102,7 @@ class FSMPlayer(Player): name = "FSM Player" - classifier = { + classifier: Dict[Text, Any] = { "memory_depth": 1, "stochastic": False, "long_run_time": False,