Merge pull request #6105 from devLotto/puzzlesolver-blank_value

puzzlesolver: break out blank tile value into a constant
This commit is contained in:
Tomas Slusny
2018-10-22 19:29:29 +02:00
committed by GitHub
4 changed files with 11 additions and 9 deletions

View File

@@ -43,6 +43,8 @@ import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import static net.runelite.api.SpriteID.MINIMAP_DESTINATION_FLAG;
import static net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver.BLANK_TILE_VALUE;
import static net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver.DIMENSION;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.game.SpriteManager;
@@ -69,9 +71,6 @@ public class PuzzleSolverOverlay extends Overlay
private static final int PUZZLE_TILE_SIZE = 39;
private static final int DOT_MARKER_SIZE = 16;
private static final int BLANK_TILE_VALUE = -1;
private static final int DIMENSION = 5;
private final Client client;
private final PuzzleSolverConfig config;
private final ScheduledExecutorService executorService;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}