Search in sources :

Example 1 with Grid

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;
}
Also used : Grid(bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid) HexagonalPlane(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexagonalPlane)

Example 2 with Grid

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);
}
Also used : Grid(bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid) DefaultEdge(org.jgrapht.graph.DefaultEdge) BOTTOM(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall.BOTTOM) GRID_SIDE_LENGTH(bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid.GRID_SIDE_LENGTH) HexNode(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode) SimpleGraph(org.jgrapht.graph.SimpleGraph) BOTTOM_RIGHT(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall.BOTTOM_RIGHT) TOP_RIGHT(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall.TOP_RIGHT) HexWall(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall) DijkstraShortestPath(org.jgrapht.alg.shortestpath.DijkstraShortestPath) Coordinates(bomb.tools.Coordinates) GraphPath(org.jgrapht.GraphPath) List(java.util.List) AbstractHexagon.calculateColumnLengthArray(bomb.modules.dh.hexamaze.hexalgorithm.storage.AbstractHexagon.calculateColumnLengthArray) Graph(org.jgrapht.Graph) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) BufferedQueue(bomb.tools.data.structures.queue.BufferedQueue) Coordinates(bomb.tools.Coordinates) GraphPath(org.jgrapht.GraphPath) DefaultEdge(org.jgrapht.graph.DefaultEdge) List(java.util.List) DijkstraShortestPath(org.jgrapht.alg.shortestpath.DijkstraShortestPath) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Grid

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());
}
Also used : Grid(bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid) Test(org.testng.annotations.Test)

Example 4 with Grid

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;
}
Also used : HexShape(bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexShape) Grid(bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid)

Example 5 with Grid

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();
}
Also used : BufferedQueue(bomb.tools.data.structures.queue.BufferedQueue) Grid(bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid)

Aggregations

Grid (bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid)7 Coordinates (bomb.tools.Coordinates)3 List (java.util.List)3 HexagonalPlane (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexagonalPlane)2 Maze (bomb.modules.dh.hexamaze.hexalgorithm.storage.Maze)2 BufferedQueue (bomb.tools.data.structures.queue.BufferedQueue)2 Pair (org.javatuples.Pair)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.testng.annotations.Test)2 AbstractHexagon.calculateColumnLengthArray (bomb.modules.dh.hexamaze.hexalgorithm.storage.AbstractHexagon.calculateColumnLengthArray)1 GRID_SIDE_LENGTH (bomb.modules.dh.hexamaze.hexalgorithm.storage.Grid.GRID_SIDE_LENGTH)1 HexNode (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode)1 HexShape (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexShape)1 HexWall (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall)1 BOTTOM (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall.BOTTOM)1 BOTTOM_RIGHT (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall.BOTTOM_RIGHT)1 TOP_RIGHT (bomb.modules.dh.hexamaze.hexalgorithm.storage.HexNode.HexWall.TOP_RIGHT)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Quartet (org.javatuples.Quartet)1