Skip to content

Commit d2184c6

Browse files
authored
Merge pull request #1453 from gaffney2010/change-cache-pattern
Change cache pattern
2 parents 8b659a6 + 9a5f9da commit d2184c6

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

axelrod/match.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ def _cache_update_required(self):
128128
A boolean to show whether the deterministic cache should be updated.
129129
"""
130130
return (
131-
not self.noise
131+
not self._stochastic
132+
and not self.noise
132133
and self._cache.mutable
133134
and not (any(Classifiers["stochastic"](p) for p in self.players))
134135
)
@@ -180,28 +181,29 @@ def play(self):
180181
turns = self.turns
181182
cache_key = (self.players[0], self.players[1])
182183

183-
if self._stochastic or not self._cached_enough_turns(cache_key, turns):
184-
for p in self.players:
185-
if self.reset:
186-
p.reset()
187-
p.set_match_attributes(**self.match_attributes)
188-
# Generate a random seed for the player, if stochastic
189-
if Classifiers["stochastic"](p):
190-
p.set_seed(self._random.random_seed_int())
191-
result = []
192-
for _ in range(turns):
193-
plays = self.simultaneous_play(
194-
self.players[0], self.players[1], self.noise
195-
)
196-
result.append(plays)
197-
198-
if self._cache_update_required:
199-
self._cache[cache_key] = result
200-
else:
201-
result = self._cache[cache_key][:turns]
184+
if self._cached_enough_turns(cache_key, turns):
185+
self.result = self._cache[cache_key][:turns]
186+
return self.result
187+
188+
for p in self.players:
189+
if self.reset:
190+
p.reset()
191+
p.set_match_attributes(**self.match_attributes)
192+
# Generate a random seed for the player, if stochastic
193+
if Classifiers["stochastic"](p):
194+
p.set_seed(self._random.random_seed_int())
195+
result = []
196+
for _ in range(turns):
197+
plays = self.simultaneous_play(
198+
self.players[0], self.players[1], self.noise
199+
)
200+
result.append(plays)
201+
202+
if self._cache_update_required:
203+
self._cache[cache_key] = result
202204

203205
self.result = result
204-
return result
206+
return self.result
205207

206208
def scores(self):
207209
"""Returns the scores of the previous Match plays."""

0 commit comments

Comments
 (0)