Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change cache pattern #1453

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
44 changes: 23 additions & 21 deletions axelrod/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def _cache_update_required(self):
A boolean to show whether the deterministic cache should be updated.
"""
return (
not self.noise
not self._stochastic
and not self.noise
and self._cache.mutable
and not (any(Classifiers["stochastic"](p) for p in self.players))
)
Expand Down Expand Up @@ -182,28 +183,29 @@ def play(self):
turns = self.turns
cache_key = (self.players[0], self.players[1])

if self._stochastic or not self._cached_enough_turns(cache_key, turns):
for p in self.players:
if self.reset:
p.reset()
p.set_match_attributes(**self.match_attributes)
# Generate a random seed for the player, if stochastic
if Classifiers["stochastic"](p):
p.set_seed(self._random.random_seed_int())
result = []
for _ in range(turns):
plays = self.simultaneous_play(
self.players[0], self.players[1], self.noise
)
result.append(plays)

if self._cache_update_required:
self._cache[cache_key] = result
else:
result = self._cache[cache_key][:turns]
if self._cached_enough_turns(cache_key, turns):
self.result = self._cache[cache_key][:turns]
return self.result

for p in self.players:
if self.reset:
p.reset()
p.set_match_attributes(**self.match_attributes)
# Generate a random seed for the player, if stochastic
if Classifiers["stochastic"](p):
p.set_seed(self._random.random_seed_int())
result = []
for _ in range(turns):
plays = self.simultaneous_play(
self.players[0], self.players[1], self.noise
)
result.append(plays)

if self._cache_update_required:
self._cache[cache_key] = result

self.result = result
return result
return self.result

def scores(self):
"""Returns the scores of the previous Match plays."""
Expand Down
Loading