Atrinik Server  4.0
Data Structures | Typedefs | Functions
maze_gen.c File Reference
#include <global.h>

Go to the source code of this file.

Data Structures

struct  free_walls_struct
 

Typedefs

typedef struct free_walls_struct free_walls_struct
 

Functions

static void fill_maze_full (char **maze, int x, int y, int xsize, int ysize, free_walls_struct *free_walls)
 
static void fill_maze_sparse (char **maze, int x, int y, int xsize, int ysize, free_walls_struct *free_walls)
 
static void make_wall_free_list (int xsize, int ysize, free_walls_struct *free_walls)
 
static void pop_wall_point (int *x, int *y, free_walls_struct *free_walls)
 
static int find_free_point (char **maze, int *x, int *y, int xc, int yc, int xsize, int ysize)
 
char ** maze_gen (int xsize, int ysize, int option)
 

Detailed Description

General maze generator.

We need to maintain a list of wall points to generate reasonable mazes: a straightforward recursive random walk maze generator would generate a map with a trivial circle-the-outer-wall solution

Definition in file maze_gen.c.

Typedef Documentation

Contains free walls in the map.

Function Documentation

static void fill_maze_full ( char **  maze,
int  x,
int  y,
int  xsize,
int  ysize,
free_walls_struct free_walls 
)
static

Recursive routine which will fill every available space in the maze with walls.

Parameters
mazeThe maze layout.
xX position where to put a wall.
yY position where to put a wall.
xsizeX maze size.
ysizeY maze size.
free_wallsFree walls list.

Definition at line 330 of file maze_gen.c.

static void fill_maze_sparse ( char **  maze,
int  x,
int  y,
int  xsize,
int  ysize,
free_walls_struct free_walls 
)
static

Recursive routine which will fill much of the maze, but will leave some free spots (possibly large) toward the center.

Parameters
mazeMaze layout.
xX position where to put a wall.
yY position where to put a wall.
xsizeX size of the maze.
ysizeY size of the maze.
free_wallsFree walls list.

Definition at line 365 of file maze_gen.c.

static int find_free_point ( char **  maze,
int *  x,
int *  y,
int  xc,
int  yc,
int  xsize,
int  ysize 
)
static

Randomly look for a square adjacent to this one where we can place a new block without closing a path.

We may only look up, down, right, or left.

Parameters
mazeCurrent maze layout.
xX coordinate of the found point.
yY coordinate of the found point.
xcX coordinate from where to look.
ycY coordinate from where to look.
xsizeX size of the maze.
ysizeY size of the maze.
Returns
-1 if no free spot, 0 otherwise.

Definition at line 214 of file maze_gen.c.

static void make_wall_free_list ( int  xsize,
int  ysize,
free_walls_struct free_walls 
)
static

Initializes the list of points where we can put walls on.

The free wall points are those outer points which aren't corners or near corners, and don't have a maze wall growing out of them already.

Parameters
xsizeX size of the map.
ysizeY size of the map.
free_wallsStructure to initialize. free_walls_struct::wall_free_size must be initialized.

Definition at line 134 of file maze_gen.c.

char** maze_gen ( int  xsize,
int  ysize,
int  option 
)

This function generates a random blocked maze with the property that there is only one path from one spot to any other, and there is always a path from one spot to any other.

Parameters
xsizeX wanted map size
ysizeY wanted map size
optionIf 0, maze will be sparse (sizeable rooms), otherwise totally filled.
Returns
a char ** array with # and . for closed and open respectively. a char value of 0 represents a blank space: a '#' is a wall.

Definition at line 69 of file maze_gen.c.

static void pop_wall_point ( int *  x,
int *  y,
free_walls_struct free_walls 
)
static

Randomly returns one of the elements from the wall point list.

Parameters
xX coordinate of the point.
yY coordinate of the point.
free_wallsFree walls list.

Definition at line 178 of file maze_gen.c.