|
|
1 | |
1 | /* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
2 | /* peterm@langmuir.eecs.berkeley.edu: this function generates a random |
2 | snake-type layout. |
3 | snake-type layout. |
3 | |
4 | |
4 | input: xsize, ysize; |
5 | input: xsize, ysize; |
5 | output: a char** array with # and . for closed and open respectively. |
6 | output: a char** array with # and . for closed and open respectively. |
… | |
… | |
41 | return maze; |
42 | return maze; |
42 | |
43 | |
43 | /* decide snake orientation--vertical or horizontal , and |
44 | /* decide snake orientation--vertical or horizontal , and |
44 | make the walls and place the doors. */ |
45 | make the walls and place the doors. */ |
45 | |
46 | |
46 | if (RANDOM () % 2) |
47 | if (rndm (2)) |
47 | { /* vertical orientation */ |
48 | { /* vertical orientation */ |
48 | int n_walls = RANDOM () % ((xsize - 5) / 3) + 1; |
49 | int n_walls = RANDOM () % ((xsize - 5) / 3) + 1; |
49 | int spacing = xsize / (n_walls + 1); |
50 | int spacing = xsize / (n_walls + 1); |
50 | int orientation = 1; |
51 | int orientation = 1; |
51 | |
52 | |
… | |
… | |
97 | orientation ^= 1; /* toggle the value of orientation */ |
98 | orientation ^= 1; /* toggle the value of orientation */ |
98 | } |
99 | } |
99 | } |
100 | } |
100 | |
101 | |
101 | /* place the exit up/down */ |
102 | /* place the exit up/down */ |
102 | if (RANDOM () % 2) |
103 | if (rndm (2)) |
103 | { |
104 | { |
104 | maze[1][1] = '<'; |
105 | maze[1][1] = '<'; |
105 | maze[xsize - 2][ysize - 2] = '>'; |
106 | maze[xsize - 2][ysize - 2] = '>'; |
106 | } |
107 | } |
107 | else |
108 | else |