Loop after solving maze
This commit is contained in:
parent
bf145830cc
commit
aaf400d881
55
main.c
55
main.c
@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user