+int
+longdeadend_p(int x1, int y1, int x2, int y2, int endwall)
+{
+ int dx = x2 - x1, dy = y2 - y1;
+ int sidewalls;
+
+ sidewalls = endwall | (endwall >> 2 | endwall << 2);
+ sidewalls = ~sidewalls & WALL_ANY;
+
+ while((maze[x2][y2] & WALL_ANY) == sidewalls)
+ {
+ x2 += dx;
+ y2 += dy;
+ }
+
+ if((maze[x2][y2] & WALL_ANY) == (sidewalls | endwall))
+ {
+ endwall = (endwall >> 2 | endwall << 2) & WALL_ANY;
+ while(x1 != x2 || y1 != y2)
+ {
+ x1 += dx;
+ y1 += dy;
+ draw_solid_square(x1, y1, endwall, sgc);
+ maze[x1][y1] |= SOLVER_VISIT;
+ }
+ return 1;
+ }
+ else
+ return 0;
+}
+
+/* Find all dead regions -- areas from which the goal cannot be reached --
+ and mark them visited. */
+void
+find_dead_regions(void)
+{
+ int x, y, flipped;
+
+ /* Find all not SOLVER_VISIT squares bordering NOT_DEAD squares
+ and mark them NOT_DEAD also. Repeat until no more such squares. */
+ maze[start_x][start_y] |= NOT_DEAD;
+
+ do
+ {
+ flipped = 0;
+ for(x = 0; x < maze_size_x; x++)
+ for(y = 0; y < maze_size_y; y++)
+ if(!(maze[x][y] & (SOLVER_VISIT | NOT_DEAD))
+ && ( (x && (maze[x-1][y] & NOT_DEAD))
+ || (y && (maze[x][y-1] & NOT_DEAD))))
+ {
+ flipped = 1;
+ maze[x][y] |= NOT_DEAD;
+ }
+ for(x = maze_size_x-1; x >= 0; x--)
+ for(y = maze_size_y-1; y >= 0; y--)
+ if(!(maze[x][y] & (SOLVER_VISIT | NOT_DEAD))
+ && ( (x != maze_size_x-1 && (maze[x+1][y] & NOT_DEAD))
+ || (y != maze_size_y-1 && (maze[x][y+1] & NOT_DEAD))))
+ {
+ flipped = 1;
+ maze[x][y] |= NOT_DEAD;
+ }
+ }
+ while(flipped);
+
+ for (y = 0; y < maze_size_y; y++)
+ for (x = 0; x < maze_size_x; x++)
+ {
+ if (maze[x][y] & NOT_DEAD)
+ maze[x][y] &= ~NOT_DEAD;
+ else if (!(maze[x][y] & SOLVER_VISIT))
+ {
+ maze[x][y] |= SOLVER_VISIT;
+ if((x < logo_x || x > logo_x + logo_width / grid_width) ||
+ (y < logo_y || y > logo_y + logo_height / grid_height))
+ {
+ if (!(maze[x][y] & WALL_ANY))
+ XFillRectangle(dpy, win, ugc,
+ border_x + bw + grid_width * x,
+ border_y + bw + grid_height * y,
+ grid_width - (bw+bw), grid_height - (bw+bw));
+ else
+ {
+ if (! (maze[x][y] & WALL_LEFT))
+ draw_solid_square(x, y, WALL_LEFT, ugc);
+ if (! (maze[x][y] & WALL_RIGHT))
+ draw_solid_square(x, y, WALL_RIGHT, ugc);
+ if (! (maze[x][y] & WALL_TOP))
+ draw_solid_square(x, y, WALL_TOP, ugc);
+ if (! (maze[x][y] & WALL_BOTTOM))
+ draw_solid_square(x, y, WALL_BOTTOM, ugc);
+ }
+ }
+ }
+ }
+ XSync(dpy, False);
+}