Skip to content

Commit f700bae

Browse files
committed
Reduce match init complexity
1 parent 42ecb93 commit f700bae

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

axelrod/match.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,41 @@ def __init__(
5656
Random seed for reproducibility
5757
"""
5858

59-
defaults = {
60-
(True, True): (DEFAULT_TURNS, 0),
61-
(True, False): (float("inf"), prob_end),
62-
(False, True): (turns, 0),
63-
(False, False): (turns, prob_end),
64-
}
65-
self.turns, self.prob_end = defaults[(turns is None, prob_end is None)]
59+
60+
self.turns, self.prob_end = turns, prob_end
61+
if prob_end is None:
62+
self.prob_end = 0
63+
if turns is None:
64+
self.turns = float("inf")
65+
if turns is None and prob_end is None:
66+
self.turns = DEFAULT_TURNS
6667

6768
self.result = []
6869
self.noise = noise
6970

70-
self.set_seed(seed)
71-
71+
self.game = game
7272
if game is None:
7373
self.game = Game()
74-
else:
75-
self.game = game
7674

75+
self._cache = deterministic_cache
7776
if deterministic_cache is None:
7877
self._cache = DeterministicCache()
79-
else:
80-
self._cache = deterministic_cache
8178

79+
self.match_attributes = match_attributes
8280
if match_attributes is None:
81+
# known_turns = inf if both prob_end and turns are None, else turns
8382
known_turns = self.turns if prob_end is None else float("inf")
8483
self.match_attributes = {
8584
"length": known_turns,
8685
"game": self.game,
8786
"noise": self.noise,
8887
}
89-
else:
90-
self.match_attributes = match_attributes
9188

9289
self.players = list(players)
9390
self.reset = reset
9491

92+
self.set_seed(seed)
93+
9594
def set_seed(self, seed):
9695
"""Sets a random seed for the Match, for reproducibility. Initializes
9796
a match-wide RNG instance which is used to propagate seeds to the Players

0 commit comments

Comments
 (0)