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

Reduce match init complexity #1454

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
28 changes: 13 additions & 15 deletions axelrod/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,40 @@ 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
Loading