I am writing a script to randomly generate a maze, and I can not even get it off the bottom, rip. I’ve written fractal mills so I am no stranger to nested FOR loops. FOR x{ FOR y }
I am utilizing my standard methods to generate the maze. To initialize it, I set the boundary of the Maze (NESW sides) to be partitions like so:
// Create
Listing<Room> row = new Listing<Room>();
for(int i=0; i<width; i++) // Columns (X-axis)
{ row.Clear();
for(int j=0; j<depth; j++){ // Rows (Z-axis)
row.Add(new Room(i, yOffset, j));
if(i==width-1){ Debug.Log("SetE: i "+i+", j "+j);
row[j].setE(-1); }
if(i==0){ Debug.Log("SetW: i "+i+", j "+j);
row[j].setW(-1); }
}
row[width-1].setN(-1);
row[0].setS(-1);
rooms.Add(row);
}
// Instantiate
for(int i=0; i<width; i++) for(int j=0; j<depth; j++)
{ // Room
Instantiate(roomGO, new Vector3(i + remodel.place.x,
yOffset + remodel.place.y, j + remodel.place.z), remodel.rotation);
// North Aspect
Instantiate(getWall(rooms[i][j],0), new Vector3(i + remodel.place.x,
yOffset + remodel.place.y, j + remodel.place.z + .75f), remodel.rotation);
// East Aspect
Instantiate(getWall(rooms[i][j],1), new Vector3(i + remodel.place.x + .75f,
yOffset + remodel.place.y, j + remodel.place.z), remodel.rotation);
// South Aspect
Instantiate(getWall(rooms[i][j],2), new Vector3(i + remodel.place.x,
yOffset + remodel.place.y, j + remodel.place.z - .75f), remodel.rotation);
// West Aspect
Instantiate(getWall(rooms[i][j],3), new Vector3(i + remodel.place.x - .75f,
yOffset + remodel.place.y, j + remodel.place.z), remodel.rotation);
}
My drawback is right here (*I believe), Traces 7 to 10:
if(i==width-1){ Debug.Log("SetE: i "+i+", j "+j);
row[j].setE(-1); }
if(i==0){ Debug.Log("SetW: i "+i+", j "+j);
row[j].setW(-1); }
The positions are appropriate. I’ve no issues with the North and South sides.
The Western partitions aren’t Instantiating. However the Jap partitions are Instantiating on each single row?
I am attempting to set all of the West and East partitions of the rooms with Coords (x=0/x=Width, z)
. The Debug.Log
traces are printing the anticipated coordinates.
Query
Why aren’t the Jap and Western partitions Instantiating correctly? Is that this Unity, C#, my Code, or my Laptop? What’s a greater method to set the partitions of my Maze?