Solve maze after generation
This commit is contained in:
parent
f4aa1bc01c
commit
f19881fd04
17
main.c
17
main.c
@ -144,6 +144,18 @@ static bool generation_visit(vec2_t c, vec2_t im)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool accessible_and_unvisited(vec2_t c, vec2_t im)
|
||||
{
|
||||
return maze[im.x][im.y].is_path && !maze[c.x][c.y].visited;
|
||||
}
|
||||
|
||||
static bool solve_visit(vec2_t c, vec2_t im)
|
||||
{
|
||||
maze[c.x][c.y].visited = true;
|
||||
maze[im.x][im.y].visited = true;
|
||||
return GOAL == c.x && GOAL == c.y;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Seed random number generation from time
|
||||
@ -187,6 +199,11 @@ int main(void)
|
||||
maze[GOAL][GOAL].is_path = true;
|
||||
random_walk(is_wall, generation_visit, gen_start);
|
||||
|
||||
// Solve
|
||||
const vec2_t solve_start = { 0, 0 };
|
||||
maze[0][0].visited = true;
|
||||
random_walk(accessible_and_unvisited, solve_visit, solve_start);
|
||||
|
||||
// Wait for window exit
|
||||
bool is_del = false;
|
||||
do {
|
||||
|
Loading…
x
Reference in New Issue
Block a user