Skip to content

Commit 294b27c

Browse files
committed
Remove unneeded aspects of Mock player.
We no longer need to set history or states in the Mock Player.
1 parent cdca2e5 commit 294b27c

File tree

2 files changed

+3
-37
lines changed

2 files changed

+3
-37
lines changed

axelrod/mock_player.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,14 @@
1010

1111

1212
class MockPlayer(Player):
13-
"""Creates a mock player that copies a history and state distribution to
14-
simulate a history of play, and then plays a given sequence of actions. If
15-
no actions are given, plays like Cooperator.
13+
"""Creates a mock player that plays a given sequence of actions. If
14+
no actions are given, plays like Cooperator. Used for testing.
1615
"""
1716

1817
name = "Mock Player"
1918

20-
def __init__(self, actions: List[Action] =None, history: List[Action] =None, state_dist: defaultdict =None) -> None:
21-
# Need to retain history for opponents that examine opponents history
22-
# Do a deep copy just to be safe
19+
def __init__(self, actions: List[Action] = None) -> None:
2320
super().__init__()
24-
if history:
25-
# Make sure we both copy the history and get the right counts
26-
# for cooperations and defections.
27-
for action in history:
28-
update_history(self, action)
29-
if state_dist:
30-
self.state_distribution = dict(state_dist)
3121
if actions:
3222
self.actions = cycle(actions)
3323
else:

axelrod/tests/unit/test_mock_player.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
class TestMockPlayer(unittest.TestCase):
1010

11-
def test_init(self):
12-
actions = [C, C, D]
13-
history = [C, C, C]
14-
state_dist = {(C, C): 2, (D, C): 1}
15-
m = MockPlayer(actions=actions, history=history, state_dist=state_dist)
16-
self.assertEqual(m.history, [C, C, C])
17-
self.assertEqual(m.state_distribution, state_dist)
18-
1911
def test_strategy(self):
2012
for action in [C, D]:
2113
m = MockPlayer(actions=[action])
@@ -28,22 +20,6 @@ def test_strategy(self):
2820
for action in actions:
2921
self.assertEqual(action, m.strategy(p2))
3022

31-
def test_history(self):
32-
t = TestOpponent()
33-
m1 = MockPlayer(actions=[C], history=[C] * 10)
34-
self.assertEqual(m1.actions.__next__(), C)
35-
self.assertEqual(m1.history, [C] * 10)
36-
self.assertEqual(m1.cooperations, 10)
37-
self.assertEqual(m1.defections, 0)
38-
self.assertEqual(m1.strategy(t), C)
39-
40-
m2 = MockPlayer(actions=[D], history=[D] * 10)
41-
self.assertEqual(m2.actions.__next__(), D)
42-
self.assertEqual(m2.history, [D] * 10)
43-
self.assertEqual(m2.cooperations, 0)
44-
self.assertEqual(m2.defections, 10)
45-
self.assertEqual(m2.strategy(t), D)
46-
4723

4824
class TestUpdateHistories(unittest.TestCase):
4925

0 commit comments

Comments
 (0)