puzzlesolver: break out -1 piece value into a constant
This commit is contained in:
@@ -31,6 +31,7 @@ import net.runelite.client.plugins.puzzlesolver.solver.pathfinding.Pathfinder;
|
||||
public class PuzzleSolver implements Runnable
|
||||
{
|
||||
public static final int DIMENSION = 5;
|
||||
public static final int BLANK_TILE_VALUE = -1;
|
||||
|
||||
private Pathfinder pathfinder;
|
||||
private PuzzleState startState;
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.runelite.client.plugins.puzzlesolver.solver.heuristics.Heuristic;
|
||||
import static net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver.DIMENSION;
|
||||
import static net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver.BLANK_TILE_VALUE;
|
||||
|
||||
public class PuzzleState
|
||||
{
|
||||
@@ -54,7 +55,7 @@ public class PuzzleState
|
||||
|
||||
for (int i = 0; i < pieces.length; i++)
|
||||
{
|
||||
if (pieces[i] == -1)
|
||||
if (pieces[i] == BLANK_TILE_VALUE)
|
||||
{
|
||||
emptyPiece = i;
|
||||
}
|
||||
@@ -89,7 +90,7 @@ public class PuzzleState
|
||||
PuzzleState state = new PuzzleState(this);
|
||||
state.parent = this;
|
||||
|
||||
state.pieces[emptyPiece - 1] = -1;
|
||||
state.pieces[emptyPiece - 1] = BLANK_TILE_VALUE;
|
||||
state.pieces[emptyPiece] = pieces[emptyPiece - 1];
|
||||
state.emptyPiece--;
|
||||
|
||||
@@ -105,7 +106,7 @@ public class PuzzleState
|
||||
PuzzleState state = new PuzzleState(this);
|
||||
state.parent = this;
|
||||
|
||||
state.pieces[emptyPiece + 1] = -1;
|
||||
state.pieces[emptyPiece + 1] = BLANK_TILE_VALUE;
|
||||
state.pieces[emptyPiece] = pieces[emptyPiece + 1];
|
||||
state.emptyPiece++;
|
||||
|
||||
@@ -121,7 +122,7 @@ public class PuzzleState
|
||||
PuzzleState state = new PuzzleState(this);
|
||||
state.parent = this;
|
||||
|
||||
state.pieces[emptyPiece - DIMENSION] = -1;
|
||||
state.pieces[emptyPiece - DIMENSION] = BLANK_TILE_VALUE;
|
||||
state.pieces[emptyPiece] = pieces[emptyPiece - DIMENSION];
|
||||
state.emptyPiece -= DIMENSION;
|
||||
|
||||
@@ -137,7 +138,7 @@ public class PuzzleState
|
||||
PuzzleState state = new PuzzleState(this);
|
||||
state.parent = this;
|
||||
|
||||
state.pieces[emptyPiece + DIMENSION] = -1;
|
||||
state.pieces[emptyPiece + DIMENSION] = BLANK_TILE_VALUE;
|
||||
state.pieces[emptyPiece] = pieces[emptyPiece + DIMENSION];
|
||||
state.emptyPiece += DIMENSION;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ package net.runelite.client.plugins.puzzlesolver.solver.heuristics;
|
||||
|
||||
import net.runelite.client.plugins.puzzlesolver.solver.PuzzleState;
|
||||
import static net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver.DIMENSION;
|
||||
import static net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver.BLANK_TILE_VALUE;
|
||||
|
||||
/**
|
||||
* An implementation of the manhattan distance heuristic function.
|
||||
@@ -51,7 +52,7 @@ public class ManhattanDistance implements Heuristic
|
||||
{
|
||||
int piece = state.getPiece(x, y);
|
||||
|
||||
if (piece == -1)
|
||||
if (piece == BLANK_TILE_VALUE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user