From aaf400d881fec4c9f729992071d45b5b100340e3 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Mon, 4 Nov 2024 00:46:09 +0000 Subject: [PATCH] Loop after solving maze --- main.c | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/main.c b/main.c index cfba17c..1e64320 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ #include #include #include +#include #define MAZE_SIZE 24 @@ -168,34 +169,38 @@ int main(void) XNextEvent(dpy, &evt); while (MapNotify != evt.type); - // Draw black box for walls - XClearWindow(dpy, window); - XSetForeground(dpy, ctx, wall_col); - XFillRectangle( - dpy, window, ctx, PX(MARGIN), PX(MARGIN), PX(GRID_SIZE + 2), - PX(GRID_SIZE + 2)); - const vec2_t exit = { GOAL + 1, GOAL }; - clear_path(exit); - XFlush(dpy); + while (1) { + // Draw black box for walls + XClearWindow(dpy, window); + XSetForeground(dpy, ctx, wall_col); + XFillRectangle( + dpy, window, ctx, PX(MARGIN), PX(MARGIN), PX(GRID_SIZE + 2), + PX(GRID_SIZE + 2)); + const vec2_t exit = { GOAL + 1, GOAL }; + clear_path(exit); + XFlush(dpy); - // Generate - memset(&maze, 0, sizeof(maze)); - const vec2_t gen_start = { GOAL, GOAL }; - maze[GOAL][GOAL].is_path = true; - clear_path(gen_start); - random_walk(is_wall, generation_visit, gen_start); + // Generate + memset(&maze, 0, sizeof(maze)); + const vec2_t gen_start = { GOAL, GOAL }; + maze[GOAL][GOAL].is_path = true; + clear_path(gen_start); + random_walk(is_wall, generation_visit, gen_start); - // Solve - const vec2_t solve_start = { 0, 0 }; - maze[0][0].visited = true; - XSetForeground(dpy, ctx, visited_col); - draw_visited(solve_start); - random_walk(accessible_and_unvisited, solve_visit, solve_start); + // Solve + const vec2_t solve_start = { 0, 0 }; + maze[0][0].visited = true; + XSetForeground(dpy, ctx, visited_col); + draw_visited(solve_start); + random_walk(accessible_and_unvisited, solve_visit, solve_start); - // Draw exit path - const int x = PX(MARGIN + GRID_SIZE + 1), y = PX(MARGIN + GRID_SIZE); - XFillRectangle(dpy, window, ctx, x, y, PX(1), PX(1)); - XFlush(dpy); + // Draw exit path + const int x = PX(MARGIN + GRID_SIZE + 1), y = PX(MARGIN + GRID_SIZE); + XFillRectangle(dpy, window, ctx, x, y, PX(1), PX(1)); + XFlush(dpy); + + sleep(1); + } // Wait for window exit bool is_del = false;