43 static int find_free_point(
char **maze,
int *x,
int *y,
int xc,
int yc,
int xsize,
int ysize);
59 char **
maze_gen(
int xsize,
int ysize,
int option,
int _unused_layers)
67 char **maze = (
char **)calloc(
sizeof(
char *), xsize);
68 for (i = 0; i < xsize; i++) {
69 maze[i] = (
char *)calloc(
sizeof(
char), ysize);
73 for (i = 0; i < xsize; i++) {
74 maze[i][0] = maze[i][ysize-1] =
'#';
76 for (j = 0; j < ysize; j++) {
77 maze[0][j] = maze[xsize-1][j] =
'#';
135 for (i = 2; i < xsize-2; i++) {
145 for (j = 2; j < ysize-2; j++) {
192 static int find_free_point(
char **maze,
int *x,
int *y,
int xc,
int yc,
int xsize,
int ysize)
199 if (yc < ysize-2 && xc > 2 && xc < xsize-2) {
200 int cleartest = (int)maze[xc][yc+1]+(
int)maze[xc-1][yc+1]+(int)maze[xc+1][yc+1];
202 cleartest += (int)maze[xc][yc+2]+(
int)maze[xc-1][yc+2]+(int)maze[xc+1][yc+2];
203 if (cleartest == 0) {
210 if (yc > 2 && xc > 2 && xc < xsize-2) {
211 int cleartest = (int)maze[xc][yc-1]+(
int)maze[xc-1][yc-1]+(int)maze[xc+1][yc-1];
213 cleartest += (int)maze[xc][yc-2]+(
int)maze[xc-1][yc-2]+(int)maze[xc+1][yc-2];
214 if (cleartest == 0) {
222 if (xc < xsize-2 && yc > 2 && yc < ysize-2) {
223 int cleartest = (int)maze[xc+1][yc]+(
int)maze[xc+1][yc-1]+(int)maze[xc+1][yc+1];
225 cleartest += (int)maze[xc+2][yc]+(
int)maze[xc+2][yc-1]+(int)maze[xc+2][yc+1];
226 if (cleartest == 0) {
234 if (xc > 2 && yc > 2 && yc < ysize-2) {
235 int cleartest = (int)maze[xc-1][yc]+(
int)maze[xc-1][yc-1]+(int)maze[xc-1][yc+1];
237 cleartest += (int)maze[xc-2][yc]+(
int)maze[xc-2][yc-1]+(int)maze[xc-2][yc+1];
238 if (cleartest == 0) {
254 switch (dirlist[count]) {
static void fill_maze_full(char **maze, int x, int y, int xsize, int ysize, free_walls_struct *)
Recursive routine which will fill every available space in the maze with walls.
int * wall_x_list
X coordinates of free spots for walls.
static void fill_maze_sparse(char **maze, int x, int y, int xsize, int ysize, free_walls_struct *)
Recursive routine which will fill much of the maze, but will leave some free spots (possibly large) t...
Global type definitions and header inclusions.
int wall_free_size
Number of items in wall_x_list and wall_y_list.
static int find_free_point(char **maze, int *x, int *y, int xc, int yc, int xsize, int ysize)
Randomly look for a square adjacent to this one where we can place a new block without closing a path...
Contains free walls in the map.
int * wall_y_list
Y coordinates of free spots for walls.
char ** maze_gen(int xsize, int ysize, int option, int _unused_layers)
This function generates a random blocked maze with the property that there is only one path from one ...
static void pop_wall_point(int *x, int *y, free_walls_struct *)
Randomly returns one of the elements from the wall point list.
static void make_wall_free_list(int xsize, int ysize, free_walls_struct *)
Inits the list of points where we can put walls on.