1 | |
|
|
2 | |
1 | |
3 | /* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
2 | /* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
4 | blocked maze with the property that there is only one path from one spot |
3 | blocked maze with the property that there is only one path from one spot |
5 | to any other, and there is always a path from one spot to any other. |
4 | to any other, and there is always a path from one spot to any other. |
6 | |
5 | |
… | |
… | |
230 | count = RANDOM () % count; |
229 | count = RANDOM () % count; |
231 | else |
230 | else |
232 | count = 0; |
231 | count = 0; |
233 | switch (dirlist[count]) |
232 | switch (dirlist[count]) |
234 | { |
233 | { |
235 | case 1: /* up */ |
234 | case 1: /* up */ |
236 | { |
235 | { |
237 | *y = yc + 1; |
236 | *y = yc + 1; |
238 | *x = xc; |
237 | *x = xc; |
239 | break; |
238 | break; |
240 | }; |
239 | }; |
241 | case 2: /* down */ |
240 | case 2: /* down */ |
242 | { |
241 | { |
243 | *y = yc - 1; |
242 | *y = yc - 1; |
244 | *x = xc; |
243 | *x = xc; |
245 | break; |
244 | break; |
246 | }; |
245 | }; |
247 | case 3: /* right */ |
246 | case 3: /* right */ |
248 | { |
247 | { |
249 | *y = yc; |
248 | *y = yc; |
250 | *x = xc + 1; |
249 | *x = xc + 1; |
251 | break; |
250 | break; |
252 | } |
251 | } |
253 | case 4: /* left */ |
252 | case 4: /* left */ |
254 | { |
253 | { |
255 | *x = xc - 1; |
254 | *x = xc - 1; |
256 | *y = yc; |
255 | *y = yc; |
257 | break; |
256 | break; |
258 | } |
257 | } |
259 | default: /* ??? */ |
258 | default: /* ??? */ |
260 | { |
259 | { |
261 | return -1; |
260 | return -1; |
262 | } |
261 | } |
263 | } |
262 | } |
264 | return 1; |
263 | return 1; |
265 | } |
264 | } |
266 | |
265 | |
267 | /* recursive routine which will fill every available space in the maze |
266 | /* recursive routine which will fill every available space in the maze |
… | |
… | |
274 | |
273 | |
275 | /* write a wall here */ |
274 | /* write a wall here */ |
276 | maze[x][y] = '#'; |
275 | maze[x][y] = '#'; |
277 | |
276 | |
278 | /* decide if we're going to pick from the wall_free_list */ |
277 | /* decide if we're going to pick from the wall_free_list */ |
279 | if (RANDOM () % 4 && wall_free_size > 0) |
278 | if (rndm (4) && wall_free_size > 0) |
280 | { |
279 | { |
281 | pop_wall_point (&xc, &yc); |
280 | pop_wall_point (&xc, &yc); |
282 | fill_maze_full (maze, xc, yc, xsize, ysize); |
281 | fill_maze_full (maze, xc, yc, xsize, ysize); |
283 | } |
282 | } |
284 | |
283 | |
… | |
… | |
300 | |
299 | |
301 | /* write a wall here */ |
300 | /* write a wall here */ |
302 | maze[x][y] = '#'; |
301 | maze[x][y] = '#'; |
303 | |
302 | |
304 | /* decide if we're going to pick from the wall_free_list */ |
303 | /* decide if we're going to pick from the wall_free_list */ |
305 | if (RANDOM () % 4 && wall_free_size > 0) |
304 | if (rndm (4) && wall_free_size > 0) |
306 | { |
305 | { |
307 | pop_wall_point (&xc, &yc); |
306 | pop_wall_point (&xc, &yc); |
308 | fill_maze_sparse (maze, xc, yc, xsize, ysize); |
307 | fill_maze_sparse (maze, xc, yc, xsize, ysize); |
309 | } |
308 | } |
310 | |
309 | |