Skip to content

Commit

Permalink
Update tests for ZD Mem2
Browse files Browse the repository at this point in the history
  • Loading branch information
marcharper committed Jul 29, 2017
1 parent 7e9f56c commit b8de0e5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
12 changes: 11 additions & 1 deletion axelrod/strategies/gambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,21 @@ class ZDMem2(Gambler):

name = "ZD-Mem2"

classifier = {
'memory_depth': 2,
'stochastic': True,
'makes_use_of': set(),
'long_run_time': False,
'inspects_source': False,
'manipulates_source': False,
'manipulates_state': False
}

def __init__(self) -> None:
pattern = [11 / 12, 4 / 11, 7 / 9, 1 / 10,
5 / 6, 3 / 11, 7 / 9, 1 / 10,
2 / 3, 1 / 11, 7 / 9, 1 / 10,
3 / 4, 2 / 11, 7 / 9, 1 / 10]
parameters = Plays(self_plays=2, op_plays=2, op_openings=2)
parameters = Plays(self_plays=2, op_plays=2, op_openings=0)

super().__init__(parameters=parameters, pattern=pattern)
46 changes: 34 additions & 12 deletions axelrod/tests/strategies/test_gambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,28 +392,50 @@ class TestZDMem2(TestPlayer):
}

def test_new_data(self):
original_data = {}
original_data = {
('', 'CC', 'CC'): 11 /12,
('', 'CC', 'CD'): 4 / 11,
('', 'CC', 'DC'): 7 / 9,
('', 'CC', 'DD'): 1 / 10,
('', 'CD', 'CC'): 5 / 6,
('', 'CD', 'CD'): 3 / 11,
('', 'CD', 'DC'): 7 / 9,
('', 'CD', 'DD'): 1 / 10,
('', 'DC', 'CC'): 2 / 3,
('', 'DC', 'CD'): 1 / 11,
('', 'DC', 'DC'): 7 / 9,
('', 'DC', 'DD'): 1 / 10 ,
('', 'DD', 'CC'): 3 / 4,
('', 'DD', 'CD'): 2 / 11,
('', 'DD', 'DC'): 7 / 9,
('', 'DD', 'DD'): 1 / 10,
}
converted_original = convert_original_to_current(original_data)
self.assertEqual(self.player().lookup_dict, converted_original)

def test_vs_defector(self):
expected = [(C, D), (C, D)] + [(D, D)] * 10
self.versus_test(axelrod.Defector(), expected_actions=expected)
seed = 5
expected = [(C, D), (C, D), (D, D), (D, D), (D, D), (D, D), (D, D),
(D, D), (C, D), (D, D)]

self.versus_test(axelrod.Defector(), expected_actions=expected,
seed=seed)

def test_vs_cooperator(self):
expected = [(C, C)] * 10
self.versus_test(axelrod.Cooperator(), expected_actions=expected)
seed = 5
expected = [(C, C), (C, C), (C, C), (C, C), (C, C), (D, C), (C, C),
(D, C), (C, C), (C, C)]

self.versus_test(axelrod.Cooperator(), expected_actions=expected,
seed=seed)

def test_vs_alternator(self):
seed = 2
expected = [(C, C), (C, D), (C, C), (D, D), (D, C), (D, D), (C, C)]
self.versus_test(axelrod.Alternator(),
expected_actions=expected,
expected = [(C, C), (C, D), (D, C), (D, D), (C, C), (C, D), (D, C)]
self.versus_test(axelrod.Alternator(), expected_actions=expected,
seed=seed)

new_seed = 1
expected[4] = (C, C)
expected[6] = (D, C)
self.versus_test(axelrod.Alternator(),
expected_actions=expected,
expected = [(C, C), (C, D), (C, C), (D, D), (D, C), (C, D), (D, C)]
self.versus_test(axelrod.Alternator(), expected_actions=expected,
seed=new_seed)
4 changes: 2 additions & 2 deletions docs/tutorials/advanced/classification_of_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ strategies::
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
70
71

Or, to find out how many strategies only use 1 turn worth of memory to
make a decision::
Expand All @@ -69,7 +69,7 @@ range of memory_depth values, we can use the 'min_memory_depth' and
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
54
55

We can also identify strategies that make use of particular properties of the
tournament. For example, here is the number of strategies that make use of the
Expand Down

0 comments on commit b8de0e5

Please sign in to comment.