Fix stuff; add new problem "Labyrinthine puzzle" from game Labyrinthine Chapter I

This commit is contained in:
Niklas Birk
2021-04-12 16:11:46 +02:00
parent 6937e28cdd
commit 3fed93055f
5 changed files with 161 additions and 31 deletions

View File

@ -0,0 +1,6 @@
package search;
enum Direction
{
TOP, RIGHT, DOWN, LEFT
}

View File

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

View File

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