]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/makemaze.c
1 /* $NetBSD: makemaze.c,v 1.2 1997/10/10 16:33:43 lukem Exp $ */
4 * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
5 * San Francisco, California
10 __RCSID("$NetBSD: makemaze.c,v 1.2 1997/10/10 16:33:43 lukem Exp $");
15 # define ISCLEAR(y,x) (Maze[y][x] == SPACE)
16 # define ODD(n) ((n) & 01)
18 static int candig
__P((int, int));
19 static void dig
__P((int, int));
20 static void dig_maze
__P((int, int));
21 static void remap
__P((void));
30 * fill maze with walls
33 while (sp
< &Maze
[HEIGHT
- 1][WIDTH
])
36 x
= rand_num(WIDTH
/ 2) * 2 + 1;
37 y
= rand_num(HEIGHT
/ 2) * 2 + 1;
45 int dirs
[NPERM
][NDIR
] = {
46 {0,1,2,3}, {3,0,1,2}, {0,2,3,1}, {0,3,2,1},
47 {1,0,2,3}, {2,3,0,1}, {0,2,1,3}, {2,3,1,0},
48 {1,0,3,2}, {1,2,0,3}, {3,1,2,0}, {2,0,3,1},
49 {1,3,0,2}, {0,3,1,2}, {1,3,2,0}, {2,0,1,3},
50 {0,1,3,2}, {3,1,0,2}, {2,1,0,3}, {1,2,3,0},
51 {2,1,3,0}, {3,0,2,1}, {3,2,0,1}, {3,2,1,0}
55 {0, 1}, {1, 0}, {0, -1}, {-1, 0}
67 Maze
[y
][x
] = SPACE
; /* Clear this spot */
68 dp
= dirs
[rand_num(NPERM
)];
81 * Is it legal to clear this spot?
90 return FALSE
; /* can't touch ODD spots */
92 if (y
< UBOUND
|| y
>= DBOUND
)
93 return FALSE
; /* Beyond vertical bounds, NO */
94 if (x
< LBOUND
|| x
>= RBOUND
)
95 return FALSE
; /* Beyond horizontal bounds, NO */
98 return FALSE
; /* Already clear, NO */
100 i
= ISCLEAR(y
, x
+ 1);
101 i
+= ISCLEAR(y
, x
- 1);
103 return FALSE
; /* Introduces cycle, NO */
104 i
+= ISCLEAR(y
+ 1, x
);
106 return FALSE
; /* Introduces cycle, NO */
107 i
+= ISCLEAR(y
- 1, x
);
109 return FALSE
; /* Introduces cycle, NO */
111 return TRUE
; /* OK */
129 for (i
= 1; i
< 4; i
++) {
134 for (i
= 0; i
< 4; i
++) {
153 if (tx
< 0 || ty
< 0 || tx
>= WIDTH
|| ty
>= HEIGHT
)
155 if (Maze
[ty
][tx
] == SPACE
)
157 Maze
[(y
+ ty
) / 2][(x
+ tx
) / 2] = SPACE
;
169 for (y
= 0; y
< HEIGHT
; y
++)
170 for (x
= 0; x
< WIDTH
; x
++) {
175 if (y
- 1 >= 0 && Maze
[y
- 1][x
] != SPACE
)
177 if (y
+ 1 < HEIGHT
&& Maze
[y
+ 1][x
] != SPACE
)
179 if (x
+ 1 < WIDTH
&& Maze
[y
][x
+ 1] != SPACE
)
181 if (x
- 1 >= 0 && Maze
[y
][x
- 1] != SPACE
)
199 *sp
= rand_num(2) ? WALL4
: WALL5
;
207 memcpy(Orig_maze
, Maze
, sizeof Maze
);