mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Filling: remove directional bias in grid generation.
The method of generating a solved Filling grid (before winnowing clues) is to loop over every square of the board, and for each one, if it has a neighbour which is part of a different region of the same size (i.e. the board is not currently legal), fix it by merging with one of its neighbours. We pick a neighbour to merge with based on the size of its region - but we always loop over the four possible neighbours in the same order, which introduces a directional bias into the breaking of ties in that comparison. Now we iterate over the four directions in random order.
This commit is contained in:
@ -414,10 +414,15 @@ retry:
|
|||||||
int merge = SENTINEL, min = maxsize - size + 1;
|
int merge = SENTINEL, min = maxsize - size + 1;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
int neighbour, neighbour_size, j;
|
int neighbour, neighbour_size, j;
|
||||||
|
int directions[4];
|
||||||
|
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
directions[j] = j;
|
||||||
|
shuffle(directions, 4, sizeof(int), rs);
|
||||||
|
|
||||||
for (j = 0; j < 4; ++j) {
|
for (j = 0; j < 4; ++j) {
|
||||||
const int x = (board[i] % w) + dx[j];
|
const int x = (board[i] % w) + dx[directions[j]];
|
||||||
const int y = (board[i] / w) + dy[j];
|
const int y = (board[i] / w) + dy[directions[j]];
|
||||||
if (x < 0 || x >= w || y < 0 || y >= h) continue;
|
if (x < 0 || x >= w || y < 0 || y >= h) continue;
|
||||||
|
|
||||||
neighbour = dsf_canonify(dsf, w*y + x);
|
neighbour = dsf_canonify(dsf, w*y + x);
|
||||||
|
Reference in New Issue
Block a user