Loop after solving maze

This commit is contained in:
Camden Dixie O'Brien 2024-11-04 00:46:09 +00:00
parent bf145830cc
commit aaf400d881

55
main.c
View File

@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#define MAZE_SIZE 24 #define MAZE_SIZE 24
@ -168,34 +169,38 @@ int main(void)
XNextEvent(dpy, &evt); XNextEvent(dpy, &evt);
while (MapNotify != evt.type); while (MapNotify != evt.type);
// Draw black box for walls while (1) {
XClearWindow(dpy, window); // Draw black box for walls
XSetForeground(dpy, ctx, wall_col); XClearWindow(dpy, window);
XFillRectangle( XSetForeground(dpy, ctx, wall_col);
dpy, window, ctx, PX(MARGIN), PX(MARGIN), PX(GRID_SIZE + 2), XFillRectangle(
PX(GRID_SIZE + 2)); dpy, window, ctx, PX(MARGIN), PX(MARGIN), PX(GRID_SIZE + 2),
const vec2_t exit = { GOAL + 1, GOAL }; PX(GRID_SIZE + 2));
clear_path(exit); const vec2_t exit = { GOAL + 1, GOAL };
XFlush(dpy); clear_path(exit);
XFlush(dpy);
// Generate // Generate
memset(&maze, 0, sizeof(maze)); memset(&maze, 0, sizeof(maze));
const vec2_t gen_start = { GOAL, GOAL }; const vec2_t gen_start = { GOAL, GOAL };
maze[GOAL][GOAL].is_path = true; maze[GOAL][GOAL].is_path = true;
clear_path(gen_start); clear_path(gen_start);
random_walk(is_wall, generation_visit, gen_start); random_walk(is_wall, generation_visit, gen_start);
// Solve // Solve
const vec2_t solve_start = { 0, 0 }; const vec2_t solve_start = { 0, 0 };
maze[0][0].visited = true; maze[0][0].visited = true;
XSetForeground(dpy, ctx, visited_col); XSetForeground(dpy, ctx, visited_col);
draw_visited(solve_start); draw_visited(solve_start);
random_walk(accessible_and_unvisited, solve_visit, solve_start); random_walk(accessible_and_unvisited, solve_visit, solve_start);
// Draw exit path // Draw exit path
const int x = PX(MARGIN + GRID_SIZE + 1), y = PX(MARGIN + GRID_SIZE); const int x = PX(MARGIN + GRID_SIZE + 1), y = PX(MARGIN + GRID_SIZE);
XFillRectangle(dpy, window, ctx, x, y, PX(1), PX(1)); XFillRectangle(dpy, window, ctx, x, y, PX(1), PX(1));
XFlush(dpy); XFlush(dpy);
sleep(1);
}
// Wait for window exit // Wait for window exit
bool is_del = false; bool is_del = false;