* Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
* San Francisco, California
# define ISCLEAR(y,x) (Maze[y][x] == SPACE)
# define ODD(n) ((n) & 01)
while (sp
< &Maze
[HEIGHT
- 1][WIDTH
])
x
= rand_num(WIDTH
/ 2) * 2 + 1;
y
= rand_num(HEIGHT
/ 2) * 2 + 1;
int dirs
[NPERM
][NDIR
] = {
{0,1,2,3}, {3,0,1,2}, {0,2,3,1}, {0,3,2,1},
{1,0,2,3}, {2,3,0,1}, {0,2,1,3}, {2,3,1,0},
{1,0,3,2}, {1,2,0,3}, {3,1,2,0}, {2,0,3,1},
{1,3,0,2}, {0,3,1,2}, {1,3,2,0}, {2,0,1,3},
{0,1,3,2}, {3,1,0,2}, {2,1,0,3}, {1,2,3,0},
{2,1,3,0}, {3,0,2,1}, {3,2,0,1}, {3,2,1,0}
{0, 1}, {1, 0}, {0, -1}, {-1, 0}
Maze
[y
][x
] = SPACE
; /* Clear this spot */
dp
= dirs
[rand_num(NPERM
)];
* Is it legal to clear this spot?
return FALSE
; /* can't touch ODD spots */
if (y
< UBOUND
|| y
>= DBOUND
)
return FALSE
; /* Beyond vertical bounds, NO */
if (x
< LBOUND
|| x
>= RBOUND
)
return FALSE
; /* Beyond horizontal bounds, NO */
return FALSE
; /* Already clear, NO */
return FALSE
; /* Introduces cycle, NO */
return FALSE
; /* Introduces cycle, NO */
return FALSE
; /* Introduces cycle, NO */
for (i
= 1; i
< 4; i
++) {
for (i
= 0; i
< 4; i
++) {
if (tx
< 0 || ty
< 0 || tx
>= WIDTH
|| ty
>= HEIGHT
)
if (Maze
[ty
][tx
] == SPACE
)
Maze
[(y
+ ty
) / 2][(x
+ tx
) / 2] = SPACE
;
for (y
= 0; y
< HEIGHT
; y
++)
for (x
= 0; x
< WIDTH
; x
++) {
if (y
- 1 >= 0 && Maze
[y
- 1][x
] != SPACE
)
if (y
+ 1 < HEIGHT
&& Maze
[y
+ 1][x
] != SPACE
)
if (x
+ 1 < WIDTH
&& Maze
[y
][x
+ 1] != SPACE
)
if (x
- 1 >= 0 && Maze
[y
][x
- 1] != SPACE
)
*sp
= rand_num(2) ? WALL4
: WALL5
;
memcpy(Orig_maze
, Maze
, sizeof Maze
);