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