From 78e804dff9595700d174d903360710d3bb5d648e Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Wed, 12 Jan 2022 14:07:01 +0100 Subject: [PATCH] Refactoring: Implements Coordinate into ai-logic --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 6 +++--- src/test/java/de/tims/fleetstorm/ai/LogicTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index a76512c..3fefa1b 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -8,12 +8,12 @@ import de.tims.fleetstorm.matchfield.Matchfield; public class Logic { - public int[] chooseField(Matchfield matchfield) { - ArrayList possibleFields = new ArrayList(); + public Coordinate chooseField(Matchfield matchfield) { + ArrayList possibleFields = new ArrayList(); for (int x = 0; x < Math.sqrt(matchfield.getSize()); x++) { for (int y = 0; y < Math.sqrt(matchfield.getSize()); y++) { if (matchfield.getState(x, y) == Coordinate.EMPTY || matchfield.getState(x, y) == Coordinate.SHIP) { - possibleFields.add(new int[] { x, y }); + possibleFields.add(new Coordinate(x, y)); } } } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 4fbb52c..7c472aa 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -16,7 +16,7 @@ class LogicTest { @Test void testFieldIsNotNull() { matchfield.createMatchfield(); - int[] calcResult = logic.chooseField(matchfield); + Coordinate calcResult = logic.chooseField(matchfield); assertNotNull(calcResult); } @@ -30,8 +30,8 @@ class LogicTest { } // matchfield.setState(0, 0, Matchfield.EMPTY); - int[] choosenField = logic.chooseField(matchfield); - int calcState = matchfield.getState(choosenField[0], choosenField[1]); + Coordinate choosenField = logic.chooseField(matchfield); + int calcState = matchfield.getState(choosenField.getX(), choosenField.getY()); assertNotEquals(calcState, Coordinate.SHOT); } }