From f700bae1623d10a56ef47e2b63b1e7903e84cc9b Mon Sep 17 00:00:00 2001 From: "T.J. Gaffney" Date: Tue, 5 Nov 2024 13:06:50 -0600 Subject: [PATCH 1/2] Reduce match init complexity --- axelrod/match.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/axelrod/match.py b/axelrod/match.py index 19c83abd9..e3c86b568 100644 --- a/axelrod/match.py +++ b/axelrod/match.py @@ -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 From 997444ed4f0750a8d598a1a54760b2d1a5b19ee5 Mon Sep 17 00:00:00 2001 From: "T.J. Gaffney" Date: Mon, 11 Nov 2024 07:58:51 -0600 Subject: [PATCH 2/2] Run black on match.py --- axelrod/match.py | 1 - 1 file changed, 1 deletion(-) diff --git a/axelrod/match.py b/axelrod/match.py index e3c86b568..00c4a44e0 100644 --- a/axelrod/match.py +++ b/axelrod/match.py @@ -56,7 +56,6 @@ def __init__( Random seed for reproducibility """ - self.turns, self.prob_end = turns, prob_end if prob_end is None: self.prob_end = 0