|
|
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 |