Reformat code

This commit is contained in:
niklas committed 2026-11-12 13:52:04 +01:00
1 parent 51c12cc0ea
commit 60c654936a
31 files changed
+262 -466

No files matched your search

+14 -28
View File
@@ -7,11 +7,9 @@ import search.Node;
import static search.SearchTestUtils.printSolution;
class AStarTest
{
class AStarTest {
@Test
void shouldReturnCorrectTargetCubekNodeHeuristic1()
{
void shouldReturnCorrectTargetCubekNodeHeuristic1() {
final int[][] state = {
{2, 0, 4},
{6, 7, 1},
@@ -32,8 +30,7 @@ class AStarTest
}
@Test
void shouldReturnCorrectTargetCubekNodeHeuristic2()
{
void shouldReturnCorrectTargetCubekNodeHeuristic2() {
final int[][] state = {
{2, 0, 4},
{6, 7, 1},
@@ -53,18 +50,14 @@ class AStarTest
printSolution(actual);
}
private int h1(final Node<int[][]> node, final Node<int[][]> target)
{
private int h1(final Node<int[][]> node, final Node<int[][]> target) {
final var value = node.getValue();
final var targetValue = target.getValue();
var counter = 0;
for (var row = 0; row < value.length; row++)
{
for (var col = 0; col < value[row].length; col++)
{
if (value[row][col] != 0 && value[row][col] != targetValue[row][col])
{
for (var row = 0; row < value.length; row++) {
for (var col = 0; col < value[row].length; col++) {
if (value[row][col] != 0 && value[row][col] != targetValue[row][col]) {
counter++;
}
}
@@ -73,19 +66,16 @@ class AStarTest
return counter;
}
private int h2(final Node<int[][]> node, final Node<int[][]> target)
{
private int h2(final Node<int[][]> node, final Node<int[][]> target) {
final var value = node.getValue();
final var targetValue = target.getValue();
var manhattanDistance = 0;
for (int i = 1; i <= 8; i++)
{
for (int i = 1; i <= 8; i++) {
final var targetPos = detectPositionOf(i, targetValue);
final var actualPos = detectPositionOf(i, value);
if (targetPos != null && actualPos != null)
{
if (targetPos != null && actualPos != null) {
final var xDistance = Math.abs(targetPos.x() - actualPos.x());
final var yDistance = Math.abs(targetPos.y() - actualPos.y());
@@ -96,14 +86,10 @@ class AStarTest
return manhattanDistance;
}
private IntPair detectPositionOf(final int i, final int[][] value)
{
for (var row = 0; row < value.length; row++)
{
for (var col = 0; col < value[row].length; col++)
{
if (value[row][col] == i)
{
private IntPair detectPositionOf(final int i, final int[][] value) {
for (var row = 0; row < value.length; row++) {
for (var col = 0; col < value[row].length; col++) {
if (value[row][col] == i) {
return new IntPair(col, row);
}
}