/* Warning: the function init_maze does not always return a maze with a solution */ /* The current algorithm uses a self-avoiding random walk. A better option may be */ /* to give random weights to the dual graph, and finite a maximal spanning tree */ /* Change constant RAND_SHIFT to change the maze */ typedef struct { short int nneighb; /* number of neighbours */ int neighb[MAZE_MAX_NGBH]; /* neighbour cells */ short int directions[MAZE_MAX_NGBH]; /* direction of neighbours */ short int north, east, south, west; /* closed walls */ short int active; /* takes value 1 if currently active in RW path */ short int tested; /* takes value 1 if tested */ short int connected; /* takes value 1 if connected to exit */ short int closed; /* takes value 1 if no untested neighbours */ } t_maze; int nmaze(int i, int j) { return(NXMAZE*j + i); } void init_maze_graph(t_maze maze[NXMAZE*NYMAZE]) { int i, j, k, n; printf("Initializing maze\n"); /* initialize neighbours */ /* in the bulk */ for (i=1; i 0)&&(!maze[n].tested)) while ((npaths > 0)) { maze[n].active = 1; printf("Cell (%i, %i) ", n%NXMAZE, n/NXMAZE); nnext = 0; for (i=0; i pathlength) j = 0; printf("j = %i\n", j); // while (deadend) if (!maze[path[j]].connected) deadend = find_maze_path(maze, path[j], newpath, &newpathlength); if (!deadend) for (n=0; n pathlength) j = 0; printf("j = %i\n", j); // while (deadend) if (!maze[path[j]].connected) deadend = find_maze_path(maze, path[j], newpath, &newpathlength); if (!deadend) for (n=0; n