# Create passages in round maze

I’ve tried to find the answer by myself, but didn’t succeeded so far.

I’ve making round maze. After instantiating every circle of walls ( for every circle - copy of the same script, because i need different number of wall parts in every circle ), the part of the wall has 10% chance to be destroyed - it creates passages by now. The problem is that it’s not a good solution, i need not more than 3 passages in every circle of walls. But with random it can be more than 3, or even zero.

So how to limit the number of passages in instantiated circles of walls? Maybe it’s better to make circle of walls by hand, without instantiating them and give every part of the wall unique name, and then make if/else with random? For example, 10% that Wall 1 will be destroyed, and if not, 10% that Wall 2 will be destroyed. And when 3 parts will be destroyed, end the chain. But isn’t it a hard way?

I cannot think of a slick way to do this. Here is a brute force way. It generates a generic list of all the possible segments, and then eliminates all but a specified number. At the top of the file put:

``````using System.Collections.Generic;
``````

Then Add this function:

``````List<int> FindHoles(int totalSegments, int holeCount) {
List<int> holes = new List<int>();
for (int i = 0; i < totalSegments; i++) {
}
while (holes.Count > holeCount) {
holes.RemoveAt (Random.Range (0,holes.Count));
}
return holes;
}
``````

Then your generation code would be:

``````void Start () {
List<int> holes = FindHoles(numberOfObjects, 3);

for (int i = 0; i < numberOfObjects; i++) {
float angle = i * Mathf.PI * 2 / numberOfObjects;
Vector3 pos = new Vector3 (Mathf.Cos (angle), 0, Mathf.Sin (angle)) * radius;

if (!holes.Contains(i)) {
GameObject Wally = Instantiate (prefab, pos, Quaternion.LookRotation(-pos)) as GameObject;
Wally.transform.parent = transform;