use of bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid in project GradleCenturion by Ultraviolet-Ninja.
the class MazeSearch method searchPillar.
private static Grid searchPillar(BufferedQueue<BufferedQueue<HexNode>> pillar, Grid grid) {
int gridSideLength = grid.getHexagon().getSideLength();
trimPillar(pillar);
HexagonalPlane copiedHexagon = new HexagonalPlane(createInitialCopy(pillar, gridSideLength), gridSideLength);
HexagonalPlane originalGrid = grid.getHexagon();
Grid output = compareFullRotation(originalGrid, copiedHexagon);
while (output == null && isNotColumnEmpty(pillar)) {
moveToNextSegment(pillar, copiedHexagon);
output = compareFullRotation(originalGrid, copiedHexagon);
}
return output;
}
use of bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid in project GradleCenturion by Ultraviolet-Ninja.
the class MazeRunner method runMaze.
@NotNull
public static List<Coordinates> runMaze(@NotNull Grid grid, @NotNull List<Coordinates> possibleExits) throws IllegalArgumentException {
Coordinates startingLocation = findStartingLocation(grid);
Graph<Coordinates, DefaultEdge> mappedGraph = convertGridToGraph(grid);
DijkstraShortestPath<Coordinates, DefaultEdge> dijkstraAlgorithm = new DijkstraShortestPath<>(mappedGraph);
return possibleExits.stream().map(exit -> dijkstraAlgorithm.getPath(startingLocation, exit)).map(GraphPath::getVertexList).min(Comparator.comparingInt(List::size)).orElseThrow(IllegalArgumentException::new);
}
use of bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid in project GradleCenturion by Ultraviolet-Ninja.
the class MazeSearchTest method nullTest.
@Test
public void nullTest() {
Grid nullState = hexagonFromLine("n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n");
Optional<Grid> emptyOptional = MazeSearch.search(maze, nullState);
assertTrue(emptyOptional.isEmpty());
}
use of bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid in project GradleCenturion by Ultraviolet-Ninja.
the class MazeSearch method compareFullRotation.
private static Grid compareFullRotation(HexagonalPlane original, HexagonalPlane copy) {
int rotation = 0;
final List<HexShape> originalShapes = convertToHexShapes(original);
do {
if (originalShapes.equals(convertToHexShapes(copy)))
return new Grid(copy, rotation);
copy.rotate();
} while (++rotation != ROTATION_COUNT);
return null;
}
use of bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid in project GradleCenturion by Ultraviolet-Ninja.
the class MazeSearch method search.
public static Optional<Grid> search(@NotNull Maze maze, @NotNull Grid grid) {
int gridSpan = grid.getHexagon().getSpan();
int lastIndex = maze.getHexagon().getSpan() - gridSpan;
BufferedQueue<BufferedQueue<HexNode>> pillar;
Grid output;
for (int offset = -1; ++offset <= lastIndex; ) {
pillar = generatePillar(maze, gridSpan, offset);
output = searchPillar(pillar, grid);
if (output != null)
return Optional.of(output);
}
return Optional.empty();
}
Aggregations