From 3924ed59b6d69a9d79ccd5f9ce4c3f163fa36d47 Mon Sep 17 00:00:00 2001 From: Philip Paquette Date: Tue, 6 Nov 2018 11:38:11 -0500 Subject: #809 - Seed for derivative maps should use same zobrist hash as parent map - Using the nb of locs and the sorted list of supply centers to compute the initial seed used to compute the zobrist hash - Child and parent maps should have compatible zobrist hash if the number of locs and the list of SCS is the same. --- diplomacy/engine/game.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diplomacy/engine/game.py b/diplomacy/engine/game.py index f386c73..3f218e4 100644 --- a/diplomacy/engine/game.py +++ b/diplomacy/engine/game.py @@ -2501,10 +2501,13 @@ class Game(Jsonable): map_locs = sorted([loc.upper() for loc in self.map.locs if self.map.area_type(loc) != 'SHUT']) nb_powers = len(map_powers) nb_locs = len(map_locs) + sorted_concat_scs = '-'.join(sorted([scs.upper() for scs in self.map.scs])) # Generating a standardized seed + # Map derivations (e.g. 'standard_age_of_empires') should have the same initial seed as their parent random_state = random.getstate() - random.seed(12345 + sum([ord(x) * 7 ** ix for ix, x in enumerate(self.map_name)]) % 2 ** 32) + map_seed = (12345 + nb_locs + sum([ord(x) * 7 ** ix for ix, x in enumerate(sorted_concat_scs)])) % 2 ** 32 + random.seed(map_seed) self.__class__.zobrist_tables[self.map_name] = { 'unit_type': [[random.randint(1, sys.maxsize) for _ in range(nb_locs)] for _ in range(2)], 'units': [[random.randint(1, sys.maxsize) for _ in range(nb_locs)] for _ in range(nb_powers)], -- cgit v1.2.3