Completed Second Step of Maze Generation
Completed the second step of maze generation. In this step, a graph is built that describes which rooms can be connected to each other by doorways. A maze is created by removing nodes (rooms) from the graph. The algorithm is incomplete, but it already produces interesting mazes comparable to DD's hand-made mazes. A few details for the future: 1. Doorways are currently carved into walls at default locations. This is just for testing and placement should be improved later. Some doorways should be removed and redundant doorways should be possible. 2. The size of a section should be assessed and the section should be discarded if it has too few rooms. 3. An NPE occurs every so often when a maze is generated. It's possible that it happens because of removing a node from the graph that is coincidentally the current node for LinkedList's iterator. The solution would be to add nodes to a list and defer removals until after the iteration is done.
This commit is contained in:
@@ -122,4 +122,40 @@ public class PartitionNode
|
||||
parent = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y, int z)
|
||||
{
|
||||
return ((minCorner.getX() <= x && x <= maxCorner.getX()) &&
|
||||
(minCorner.getY() <= y && y <= maxCorner.getY()) &&
|
||||
(minCorner.getZ() <= z && z <= maxCorner.getZ()));
|
||||
}
|
||||
|
||||
public PartitionNode findPoint(int x, int y, int z)
|
||||
{
|
||||
// Find the lowest node that contains the specified point or return null
|
||||
if (this.contains(x, y, z))
|
||||
{
|
||||
return this.findPointInternal(x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PartitionNode findPointInternal(int x, int y, int z)
|
||||
{
|
||||
if (leftChild != null && leftChild.contains(x, y, z))
|
||||
{
|
||||
return leftChild.findPointInternal(x, y, z);
|
||||
}
|
||||
else if (rightChild != null && rightChild.contains(x, y, z))
|
||||
{
|
||||
return rightChild.findPointInternal(x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user