| 1 |
root |
1.4 |
|
| 2 |
elmex |
1.1 |
/* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
| 3 |
|
|
snake-type layout. |
| 4 |
|
|
|
| 5 |
|
|
input: xsize, ysize; |
| 6 |
|
|
output: a char** array with # and . for closed and open respectively. |
| 7 |
|
|
|
| 8 |
|
|
a char value of 0 represents a blank space: a '#' is |
| 9 |
|
|
a wall. |
| 10 |
|
|
|
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
|
|
#include <global.h> |
| 14 |
root |
1.7 |
#include "random_map.h" |
| 15 |
|
|
#include "rproto.h" |
| 16 |
elmex |
1.1 |
|
| 17 |
root |
1.8 |
void |
| 18 |
root |
1.9 |
make_snake_layout (Layout maze, int options) |
| 19 |
root |
1.2 |
{ |
| 20 |
|
|
int i, j; |
| 21 |
elmex |
1.1 |
|
| 22 |
root |
1.8 |
maze->clear (); |
| 23 |
|
|
maze->border (); |
| 24 |
elmex |
1.1 |
|
| 25 |
root |
1.8 |
int xsize = maze->w; |
| 26 |
|
|
int ysize = maze->h; |
| 27 |
elmex |
1.1 |
|
| 28 |
|
|
/* Bail out if the size is too small to make a snake. */ |
| 29 |
root |
1.2 |
if (xsize < 8 || ysize < 8) |
| 30 |
root |
1.8 |
return; |
| 31 |
elmex |
1.1 |
|
| 32 |
|
|
/* decide snake orientation--vertical or horizontal , and |
| 33 |
|
|
make the walls and place the doors. */ |
| 34 |
|
|
|
| 35 |
root |
1.10 |
if (rmg_rndm (2)) |
| 36 |
root |
1.2 |
{ /* vertical orientation */ |
| 37 |
root |
1.10 |
int n_walls = rmg_rndm (xsize - 5) / 3 + 1; |
| 38 |
root |
1.2 |
int spacing = xsize / (n_walls + 1); |
| 39 |
|
|
int orientation = 1; |
| 40 |
|
|
|
| 41 |
|
|
for (i = spacing; i < xsize - 3; i += spacing) |
| 42 |
|
|
{ |
| 43 |
|
|
if (orientation) |
| 44 |
|
|
{ |
| 45 |
|
|
for (j = 1; j < ysize - 2; j++) |
| 46 |
root |
1.7 |
maze[i][j] = '#'; |
| 47 |
|
|
|
| 48 |
root |
1.2 |
maze[i][j] = 'D'; |
| 49 |
|
|
} |
| 50 |
|
|
else |
| 51 |
|
|
{ |
| 52 |
|
|
for (j = 2; j < ysize; j++) |
| 53 |
root |
1.7 |
maze[i][j] = '#'; |
| 54 |
|
|
|
| 55 |
root |
1.2 |
maze[i][1] = 'D'; |
| 56 |
|
|
} |
| 57 |
root |
1.7 |
|
| 58 |
root |
1.2 |
orientation ^= 1; /* toggle the value of orientation */ |
| 59 |
elmex |
1.1 |
} |
| 60 |
|
|
} |
| 61 |
root |
1.2 |
else |
| 62 |
|
|
{ /* horizontal orientation */ |
| 63 |
root |
1.10 |
int n_walls = rmg_rndm (ysize - 5) / 3 + 1; |
| 64 |
root |
1.2 |
int spacing = ysize / (n_walls + 1); |
| 65 |
|
|
int orientation = 1; |
| 66 |
|
|
|
| 67 |
|
|
for (i = spacing; i < ysize - 3; i += spacing) |
| 68 |
|
|
{ |
| 69 |
|
|
if (orientation) |
| 70 |
|
|
{ |
| 71 |
|
|
for (j = 1; j < xsize - 2; j++) |
| 72 |
root |
1.7 |
maze[j][i] = '#'; |
| 73 |
|
|
|
| 74 |
root |
1.2 |
maze[j][i] = 'D'; |
| 75 |
|
|
} |
| 76 |
|
|
else |
| 77 |
|
|
{ |
| 78 |
|
|
for (j = 2; j < xsize; j++) |
| 79 |
root |
1.7 |
maze[j][i] = '#'; |
| 80 |
|
|
|
| 81 |
root |
1.2 |
maze[1][i] = 'D'; |
| 82 |
|
|
} |
| 83 |
root |
1.7 |
|
| 84 |
root |
1.2 |
orientation ^= 1; /* toggle the value of orientation */ |
| 85 |
elmex |
1.1 |
} |
| 86 |
|
|
} |
| 87 |
root |
1.2 |
|
| 88 |
elmex |
1.1 |
/* place the exit up/down */ |
| 89 |
root |
1.10 |
if (rmg_rndm (2)) |
| 90 |
root |
1.2 |
{ |
| 91 |
|
|
maze[1][1] = '<'; |
| 92 |
|
|
maze[xsize - 2][ysize - 2] = '>'; |
| 93 |
|
|
} |
| 94 |
elmex |
1.1 |
else |
| 95 |
root |
1.2 |
{ |
| 96 |
|
|
maze[1][1] = '>'; |
| 97 |
|
|
maze[xsize - 2][ysize - 2] = '<'; |
| 98 |
|
|
} |
| 99 |
elmex |
1.1 |
} |
| 100 |
root |
1.7 |
|