Skip to content

Commit

Permalink
Reduce match init complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffney2010 committed Nov 5, 2024
1 parent 42ecb93 commit f700bae
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions axelrod/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,41 @@ def __init__(
Random seed for reproducibility
"""

defaults = {
(True, True): (DEFAULT_TURNS, 0),
(True, False): (float("inf"), prob_end),
(False, True): (turns, 0),
(False, False): (turns, prob_end),
}
self.turns, self.prob_end = defaults[(turns is None, prob_end is None)]

self.turns, self.prob_end = turns, prob_end
if prob_end is None:
self.prob_end = 0
if turns is None:
self.turns = float("inf")
if turns is None and prob_end is None:
self.turns = DEFAULT_TURNS

self.result = []
self.noise = noise

self.set_seed(seed)

self.game = game
if game is None:
self.game = Game()
else:
self.game = game

self._cache = deterministic_cache
if deterministic_cache is None:
self._cache = DeterministicCache()
else:
self._cache = deterministic_cache

self.match_attributes = match_attributes
if match_attributes is None:
# known_turns = inf if both prob_end and turns are None, else turns
known_turns = self.turns if prob_end is None else float("inf")
self.match_attributes = {
"length": known_turns,
"game": self.game,
"noise": self.noise,
}
else:
self.match_attributes = match_attributes

self.players = list(players)
self.reset = reset

self.set_seed(seed)

def set_seed(self, seed):
"""Sets a random seed for the Match, for reproducibility. Initializes
a match-wide RNG instance which is used to propagate seeds to the Players
Expand Down

0 comments on commit f700bae

Please sign in to comment.