Skip to content

Commit 75f6e77

Browse files
authored
Merge pull request #1454 from gaffney2010/match-init
Reduce match init complexity
2 parents 6514780 + 997444e commit 75f6e77

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

axelrod/match.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,40 @@ 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+
self.turns, self.prob_end = turns, prob_end
60+
if prob_end is None:
61+
self.prob_end = 0
62+
if turns is None:
63+
self.turns = float("inf")
64+
if turns is None and prob_end is None:
65+
self.turns = DEFAULT_TURNS
6666

6767
self.result = []
6868
self.noise = noise
6969

70-
self.set_seed(seed)
71-
70+
self.game = game
7271
if game is None:
7372
self.game = Game()
74-
else:
75-
self.game = game
7673

74+
self._cache = deterministic_cache
7775
if deterministic_cache is None:
7876
self._cache = DeterministicCache()
79-
else:
80-
self._cache = deterministic_cache
8177

78+
self.match_attributes = match_attributes
8279
if match_attributes is None:
80+
# known_turns = inf if both prob_end and turns are None, else turns
8381
known_turns = self.turns if prob_end is None else float("inf")
8482
self.match_attributes = {
8583
"length": known_turns,
8684
"game": self.game,
8785
"noise": self.noise,
8886
}
89-
else:
90-
self.match_attributes = match_attributes
9187

9288
self.players = list(players)
9389
self.reset = reset
9490

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

0 commit comments

Comments
 (0)