/* Advance the solution marking by one cell. */ void maze_mark_advance_cell(struct maze *mp, int cr, int cc, int *nr, int *nc) { cell_t *cp = maze_get_cell_addr(mp, cr, cc); *cp |= SOLUTION; if (maze_get_cell_distance(mp, cr, cc) == 1) ABORT(); if (!maze_is_prev_cell(mp, cr, cc, cr - 1, cc, nr, nc) && !maze_is_prev_cell(mp, cr, cc, cr + 1, cc, nr, nc) && !maze_is_prev_cell(mp, cr, cc, cr, cc - 1, nr, nc) && !maze_is_prev_cell(mp, cr, cc, cr, cc + 1, nr, nc)) ABORT(); }
/* * Mark the maze's solution, working from the end to the beginning. * Returns the length of the solution, including the two endpoints. * A length of zero implies an unsolvable maze. */ int maze_mark_solution(struct maze *mp, int startrow, int startcol, int endrow, int endcol) { int cr; int cc; cell_t *cp; int nr = endrow; int nc = endcol; for (;;) { cr = nr; cc = nc; cp = maze_get_cell_addr(mp, cr, cc); *cp |= SOLUTION; if (cr == startrow && cc == startcol) return maze_get_cell_distance(mp, endrow, endcol); if (!maze_is_prev_cell(mp, cr, cc, cr - 1, cc, &nr, &nc) && !maze_is_prev_cell(mp, cr, cc, cr + 1, cc, &nr, &nc) && !maze_is_prev_cell(mp, cr, cc, cr, cc - 1, &nr, &nc) && !maze_is_prev_cell(mp, cr, cc, cr, cc + 1, &nr, &nc)) ABORT(); } }