Added a failsafe for cases where the walker population randomly dies out

This commit is contained in:
Charles Peyrat 2020-12-07 00:24:31 +01:00
parent 2a1be4233b
commit 7cfe55f42c

View File

@ -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