From 7cfe55f42cd23c7fbb0d2254abceaaaf837e8ecd Mon Sep 17 00:00:00 2001 From: Charles Peyrat Date: Mon, 7 Dec 2020 00:24:31 +0100 Subject: [PATCH] Added a failsafe for cases where the walker population randomly dies out --- dungeonbattle/mapgeneration/randomwalk.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dungeonbattle/mapgeneration/randomwalk.py b/dungeonbattle/mapgeneration/randomwalk.py index 60baaba..3aaad70 100644 --- a/dungeonbattle/mapgeneration/randomwalk.py +++ b/dungeonbattle/mapgeneration/randomwalk.py @@ -66,6 +66,7 @@ class Generator: # next iteration of the main loop next_walker_pop = [] + failsafe = choice(walkers) for walker in walkers: if grid[walker.y][walker.x] == Tile.WALL: count += 1 @@ -76,6 +77,10 @@ class Generator: if random() > self.params["death_chance"]: next_walker_pop.append(walker) + # we make sure to never kill all walkers + if next_walker_pop == []: + next_walker_pop.append(failsafe) + # we use a second loop for spliting so we're not bothered by cases # like a walker not spliting because we hit the population cap even # though the next one would have died and freed a place