aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2018-11-06 11:38:11 -0500
committerPhilip Paquette <pcpaquette@gmail.com>2019-04-18 11:20:00 -0400
commit3924ed59b6d69a9d79ccd5f9ce4c3f163fa36d47 (patch)
tree4cdaa1010e8597d302d1030ee3e821f738c8443d
parent7205be751bf90123cb3f2edea842d0529d5f070f (diff)
#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.
-rw-r--r--diplomacy/engine/game.py5
1 files changed, 4 insertions, 1 deletions
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)],