Skip to content

Commit

Permalink
Merge pull request #1453 from gaffney2010/change-cache-pattern
Browse files Browse the repository at this point in the history
Change cache pattern
  • Loading branch information
gaffney2010 authored Nov 30, 2024
2 parents 8b659a6 + 9a5f9da commit d2184c6
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions axelrod/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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 @@ -180,28 +181,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

0 comments on commit d2184c6

Please sign in to comment.