aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2021-03-29 20:50:28 +0100
committerSimon Tatham <anakin@pobox.com>2021-03-29 21:00:13 +0100
commit0f3c2f7cd4c59e1eee6c44d800e266b57e2ec33f (patch)
tree5c27fd8d6cefd5b7c7653a0d2fa2ca5629d686ee
parent083de051cbc88f391c6bd28481b856013e293ce9 (diff)
downloadpuzzles-0f3c2f7cd4c59e1eee6c44d800e266b57e2ec33f.zip
puzzles-0f3c2f7cd4c59e1eee6c44d800e266b57e2ec33f.tar.gz
puzzles-0f3c2f7cd4c59e1eee6c44d800e266b57e2ec33f.tar.bz2
puzzles-0f3c2f7cd4c59e1eee6c44d800e266b57e2ec33f.tar.xz
Filling grid gen: slightly randomise neighbour selection.
This is another modification to the same piece of code as the previous commit. Previously, a square with a neighbour in a same-sized region was fixed by choosing a neighbour to merge it with that was part of the smallest region. Now, it's _usually_ that, but sometimes it can be a larger neighbour instead. Partly, I hope this might remove a potential source of regularity in the random grids. But mostly, it prevents the grid generator from hanging completely on 2x2 grids (e.g. if you gave "2x2#12345" in the previous state of the code), because with the previous 'always minimal' rule, the generator would merge together two squares of the 2x2 grid, then the other two, and then (due to maxsize==3) it would have no merge remaining to clear the final error. Now, every so often, it will take the unusual option of making a size-3 region instead, which allows game generation to succeed.
-rw-r--r--filling.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/filling.c b/filling.c
index ffa3ab1..06f6982 100644
--- a/filling.c
+++ b/filling.c
@@ -434,7 +434,7 @@ retry:
/* find the smallest neighbour to merge with, which
* wouldn't make the region too large. (This is
* guaranteed by the initial value of `min'.) */
- if (neighbour_size < min) {
+ if (neighbour_size < min && random_upto(rs, 10)) {
min = neighbour_size;
merge = neighbour;
}