Fix stuff; add new problem "Labyrinthine puzzle" from game Labyrinthine Chapter I
This commit is contained in:
6
src/search/Direction.java
Normal file
6
src/search/Direction.java
Normal file
@ -0,0 +1,6 @@
|
||||
package search;
|
||||
|
||||
enum Direction
|
||||
{
|
||||
TOP, RIGHT, DOWN, LEFT
|
||||
}
|
@ -28,8 +28,8 @@ public class EightPuzzleNode extends Node<int[][]>
|
||||
{
|
||||
final var successors = new ArrayList<Node<int[][]>>();
|
||||
final var emptyPosition = Objects.requireNonNull(detectEmptyPosition());
|
||||
final var x = emptyPosition.getX();
|
||||
final var y = emptyPosition.getY();
|
||||
final var x = emptyPosition.x();
|
||||
final var y = emptyPosition.y();
|
||||
|
||||
for (final var dir : Direction.values())
|
||||
{
|
||||
@ -124,13 +124,8 @@ public class EightPuzzleNode extends Node<int[][]>
|
||||
|
||||
private void swapStateField(final int[][] newState, final IntPair emptyPos, final IntPair posToSwap)
|
||||
{
|
||||
final var tmp = newState[posToSwap.getY()][posToSwap.getX()];
|
||||
newState[posToSwap.getY()][posToSwap.getX()] = newState[emptyPos.getY()][emptyPos.getX()];
|
||||
newState[emptyPos.getY()][emptyPos.getX()] = tmp;
|
||||
}
|
||||
|
||||
private enum Direction
|
||||
{
|
||||
TOP, RIGHT, DOWN, LEFT
|
||||
final var tmp = newState[posToSwap.y()][posToSwap.x()];
|
||||
newState[posToSwap.y()][posToSwap.x()] = newState[emptyPos.y()][emptyPos.x()];
|
||||
newState[emptyPos.y()][emptyPos.x()] = tmp;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,5 @@
|
||||
package search;
|
||||
|
||||
public class IntPair
|
||||
public record IntPair(int x, int y)
|
||||
{
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
public IntPair(final int x, final int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
public int getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user