Skip to content

Commit

Permalink
Fix copperwater#56: failed mazewalk
Browse files Browse the repository at this point in the history
walkfrom's recursion worked in such a way that it could go back to every
level _but_ the very first position it started from. This meant that if
its first move could get it stuck between a room and a corner of the
map, the rest of the map would go unfilled.

This behavior can be reproduced consistently by placing a room with
roompos.x = 5, roompos.y = 3, then starting the mazewalk with mm.x = 3
and mm.y = 5.

Adjust walkfrom so that it doesn't irrevocably commit to a direction
before recursing, which should solve this problem.  Fixes copperwater#56.
  • Loading branch information
entrez committed Nov 10, 2021
1 parent 163ff07 commit 2a64df9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/mkmaze.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ walkfrom(int x, int y, schar typ)
void
walkfrom(int x, int y, schar typ)
{
int q, a, dir;
int q, a, dir, move_x, move_y;
int dirs[4];

if (!typ) {
Expand All @@ -1459,17 +1459,17 @@ walkfrom(int x, int y, schar typ)
}

while (1) {
q = 0;
q = 0, move_x = x, move_y = y;
for (a = 0; a < 4; a++)
if (okay(x, y, a))
dirs[q++] = a;
if (!q)
return;
dir = dirs[rn2(q)];
mz_move(x, y, dir);
levl[x][y].typ = typ;
mz_move(x, y, dir);
walkfrom(x, y, typ);
mz_move(move_x, move_y, dir);
levl[move_x][move_y].typ = typ;
mz_move(move_x, move_y, dir);
walkfrom(move_x, move_y, typ);
}
}
#endif /* ?MICRO */
Expand Down

0 comments on commit 2a64df9

Please sign in to comment.