Search in sources :

Example 6 with PuzzleState

use of net.runelite.client.plugins.puzzlesolver.solver.PuzzleState in project runelite by runelite.

the class IDAStar method search.

private PuzzleState search(PuzzleState node, int g, int bound) {
    int h = node.getHeuristicValue(getHeuristic());
    int f = g + h;
    if (f > bound) {
        return null;
    }
    if (h == 0) {
        return node;
    }
    for (PuzzleState successor : node.computeMoves()) {
        PuzzleState t = search(successor, g + 1, bound);
        if (t != null) {
            return t;
        }
    }
    return null;
}
Also used : PuzzleState(net.runelite.client.plugins.puzzlesolver.solver.PuzzleState)

Example 7 with PuzzleState

use of net.runelite.client.plugins.puzzlesolver.solver.PuzzleState in project runelite by runelite.

the class PuzzleSolverTest method testSolver.

@Test
public void testSolver() {
    for (PuzzleState state : START_STATES) {
        PuzzleSolver solver = new PuzzleSolver(new IDAStar(new ManhattanDistance()), state);
        solver.run();
        assertTrue(solver.hasSolution());
        assertFalse(solver.hasFailed());
        assertTrue(solver.getStep(solver.getStepCount() - 1).hasPieces(FINISHED_STATE));
    }
}
Also used : IDAStar(net.runelite.client.plugins.puzzlesolver.solver.pathfinding.IDAStar) PuzzleState(net.runelite.client.plugins.puzzlesolver.solver.PuzzleState) PuzzleSolver(net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver) ManhattanDistance(net.runelite.client.plugins.puzzlesolver.solver.heuristics.ManhattanDistance) Test(org.junit.Test)

Aggregations

PuzzleState (net.runelite.client.plugins.puzzlesolver.solver.PuzzleState)7 PuzzleSolver (net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver)2 ManhattanDistance (net.runelite.client.plugins.puzzlesolver.solver.heuristics.ManhattanDistance)2 IDAStar (net.runelite.client.plugins.puzzlesolver.solver.pathfinding.IDAStar)2 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 ItemContainer (net.runelite.api.ItemContainer)1 Widget (net.runelite.api.widgets.Widget)1 BackgroundComponent (net.runelite.client.ui.overlay.components.BackgroundComponent)1 TextComponent (net.runelite.client.ui.overlay.components.TextComponent)1 Test (org.junit.Test)1