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 | snake-type layout. |
3 | snake-type layout. |
5 | |
4 | |
6 | input: xsize, ysize; |
5 | input: xsize, ysize; |
… | |
… | |
43 | return maze; |
42 | return maze; |
44 | |
43 | |
45 | /* decide snake orientation--vertical or horizontal , and |
44 | /* decide snake orientation--vertical or horizontal , and |
46 | make the walls and place the doors. */ |
45 | make the walls and place the doors. */ |
47 | |
46 | |
48 | if (RANDOM () % 2) |
47 | if (rndm (2)) |
49 | { /* vertical orientation */ |
48 | { /* vertical orientation */ |
50 | int n_walls = RANDOM () % ((xsize - 5) / 3) + 1; |
49 | int n_walls = rndm (xsize - 5) / 3 + 1; |
51 | int spacing = xsize / (n_walls + 1); |
50 | int spacing = xsize / (n_walls + 1); |
52 | int orientation = 1; |
51 | int orientation = 1; |
53 | |
52 | |
54 | for (i = spacing; i < xsize - 3; i += spacing) |
53 | for (i = spacing; i < xsize - 3; i += spacing) |
55 | { |
54 | { |
… | |
… | |
72 | orientation ^= 1; /* toggle the value of orientation */ |
71 | orientation ^= 1; /* toggle the value of orientation */ |
73 | } |
72 | } |
74 | } |
73 | } |
75 | else |
74 | else |
76 | { /* horizontal orientation */ |
75 | { /* horizontal orientation */ |
77 | int n_walls = RANDOM () % ((ysize - 5) / 3) + 1; |
76 | int n_walls = rndm (ysize - 5) / 3 + 1; |
78 | int spacing = ysize / (n_walls + 1); |
77 | int spacing = ysize / (n_walls + 1); |
79 | int orientation = 1; |
78 | int orientation = 1; |
80 | |
79 | |
81 | for (i = spacing; i < ysize - 3; i += spacing) |
80 | for (i = spacing; i < ysize - 3; i += spacing) |
82 | { |
81 | { |
… | |
… | |
99 | orientation ^= 1; /* toggle the value of orientation */ |
98 | orientation ^= 1; /* toggle the value of orientation */ |
100 | } |
99 | } |
101 | } |
100 | } |
102 | |
101 | |
103 | /* place the exit up/down */ |
102 | /* place the exit up/down */ |
104 | if (RANDOM () % 2) |
103 | if (rndm (2)) |
105 | { |
104 | { |
106 | maze[1][1] = '<'; |
105 | maze[1][1] = '<'; |
107 | maze[xsize - 2][ysize - 2] = '>'; |
106 | maze[xsize - 2][ysize - 2] = '>'; |
108 | } |
107 | } |
109 | else |
108 | else |