Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion axelrod/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def __init__(self, memory_depth, plays=None, coplays=None):
memory_depth, int:
length of history to retain
"""
super().__init__(plays=plays, coplays=coplays)
self.memory_depth = memory_depth
super().__init__(plays=plays, coplays=coplays)

def flip_plays(self):
"""Creates a flipped plays history for use with DualTransformer."""
Expand All @@ -138,3 +138,11 @@ def append(self, play, coplay):
first_play, first_coplay = self._plays.pop(0), self._coplays.pop(0)
self._actions[first_play] -= 1
self._state_distribution[(first_play, first_coplay)] -= 1

def extend(self, new_plays, new_coplays):
"""A function that emulates list.extend, respecting the stated memory depth."""
self._plays.extend(new_plays)
self._coplays.extend(new_coplays)
if len(self._plays) > self.memory_depth:
self._plays = self._plays[-self.memory_depth :]
self._coplays = self._coplays[-self.memory_depth :]
4 changes: 2 additions & 2 deletions axelrod/tests/unit/test_game.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

import numpy as np
from hypothesis import given, settings
from hypothesis import HealthCheck, given, settings
from hypothesis.extra.numpy import array_shapes, arrays
from hypothesis.strategies import integers

Expand Down Expand Up @@ -123,7 +123,7 @@ def test_random_repr(self, asymgame):
self.assertEqual(expected_repr, str(asymgame))

@given(asymgame1=asymmetric_games(), asymgame2=asymmetric_games())
@settings(max_examples=5)
@settings(max_examples=5, suppress_health_check=(HealthCheck.too_slow,))
def test_equality(self, asymgame1, asymgame2):
"""Tests equality of AsymmetricGames based on their matrices."""
self.assertFalse(asymgame1 == "foo")
Expand Down
11 changes: 11 additions & 0 deletions axelrod/tests/unit/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,14 @@ def test_memory_depth(self):
h.state_distribution,
Counter({(D, D): 1, (C, D): 1, (D, C): 1, (C, C): 0}),
)

def test_extend(self):
h1 = LimitedHistory(3, plays=[C, C, D], coplays=[C, C, C])
self.assertEqual(list(h1), [C, C, D])
h1.extend([C, C], [D, D])
self.assertEqual(list(h1), [D, C, C])
h1.extend([D, C], [D, D])
self.assertEqual(list(h1), [C, D, C])
h1.memory_depth = 4
h1.extend([D, C], [D, D])
self.assertEqual(list(h1), [D, C, D, C])
Loading