2 * Copyright (c) 1983-2003, Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University of California, San Francisco nor
15 * the names of its contributors may be used to endorse or promote
16 * products derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $OpenBSD: makemaze.c,v 1.6 2003/06/11 08:45:33 pjanzen Exp $
32 * $NetBSD: makemaze.c,v 1.2 1997/10/10 16:33:43 lukem Exp $
33 * $DragonFly: src/games/hunt/huntd/makemaze.c,v 1.2 2008/09/04 16:12:51 swildner Exp $
42 # define ISCLEAR(y,x) (Maze[y][x] == SPACE)
43 # define ODD(n) ((n) & 01)
45 static void dig_maze(int, int);
46 static void remap(void);
55 * fill maze with walls
58 while (sp
< &Maze
[HEIGHT
- 1][WIDTH
])
61 x
= rand_num(WIDTH
/ 2) * 2 + 1;
62 y
= rand_num(HEIGHT
/ 2) * 2 + 1;
70 int dirs
[NPERM
][NDIR
] = {
71 {0,1,2,3}, {3,0,1,2}, {0,2,3,1}, {0,3,2,1},
72 {1,0,2,3}, {2,3,0,1}, {0,2,1,3}, {2,3,1,0},
73 {1,0,3,2}, {1,2,0,3}, {3,1,2,0}, {2,0,3,1},
74 {1,3,0,2}, {0,3,1,2}, {1,3,2,0}, {2,0,1,3},
75 {0,1,3,2}, {3,1,0,2}, {2,1,0,3}, {1,2,3,0},
76 {2,1,3,0}, {3,0,2,1}, {3,2,0,1}, {3,2,1,0}
80 {0, 1}, {1, 0}, {0, -1}, {-1, 0}
84 dig_maze(int x
, int y
)
97 for (i
= 1; i
< 4; i
++) {
102 for (i
= 0; i
< 4; i
++) {
121 if (tx
< 0 || ty
< 0 || tx
>= WIDTH
|| ty
>= HEIGHT
)
123 if (Maze
[ty
][tx
] == SPACE
)
125 Maze
[(y
+ ty
) / 2][(x
+ tx
) / 2] = SPACE
;
137 for (y
= 0; y
< HEIGHT
; y
++)
138 for (x
= 0; x
< WIDTH
; x
++) {
142 /* Find occupied adjacent cells. */
144 if (y
- 1 >= 0 && Maze
[y
- 1][x
] != SPACE
)
146 if (y
+ 1 < HEIGHT
&& Maze
[y
+ 1][x
] != SPACE
)
148 if (x
+ 1 < WIDTH
&& Maze
[y
][x
+ 1] != SPACE
)
150 if (x
- 1 >= 0 && Maze
[y
][x
- 1] != SPACE
)
167 *sp
= rand_num(2) ? WALL4
: WALL5
;
174 memcpy(Orig_maze
, Maze
, sizeof Orig_maze
);