diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index 67a96ff..5534407 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -46,6 +46,7 @@ public class Logic { } Random randy = new Random(); lastShot = possibleFields.get(randy.nextInt(possibleFields.size())); + target = possibleFields.get(randy.nextInt(possibleFields.size())); if (lastShot.getState() == Coordinate.SHIP) { foundShip = true; } @@ -186,4 +187,13 @@ public class Logic { public void setClearedLeft(boolean b) { this.clearedLeft = b; } + + public Coordinate getTarget() { + return target; + } + + public void setTarget(Coordinate target) { + this.target = target; + } + } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 1d1df19..46acee3 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -1,17 +1,12 @@ package de.tims.fleetstorm.ai; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.ArrayList; -import java.util.stream.Stream; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import de.tims.fleetstorm.matchfield.Coordinate; import de.tims.fleetstorm.matchfield.Matchfield; @@ -90,7 +85,6 @@ class LogicTest { Coordinate result = logic.getLastShot(); assertEquals(result, expectedResult); - } @Test @@ -261,25 +255,23 @@ class LogicTest { } - @ParameterizedTest(name = "choose the right Coordinate after Hit") - @MethodSource("getCorrectNext") - void testNextChooseFieldAfterHit(String testName, Coordinate center, Coordinate expectedResult) { + @Test + void testChooseFieldAboveAfterHit() { Logic logic = new Logic(); int size = 4; + Coordinate center = new Coordinate(2, 2); + Coordinate expectedResult = new Coordinate(2, 3); Matchfield matchfield = new Matchfield(size); matchfield.createMatchfield(); matchfield.setState(center, Coordinate.HIT); matchfield.setState(expectedResult, Coordinate.HIT); logic.setMatchfield(matchfield); logic.setLastShot(center); + logic.setTarget(center); logic.setFoundShip(true); Coordinate result = logic.chooseField(logic.getEverySecondField()); - assertThat(result).describedAs(testName).isEqualTo(expectedResult); + assertEquals(result, expectedResult); } - static Stream getCorrectNext() { - return Stream - .of(Arguments.of("center (2/2) - target should be (2,3)", new Coordinate(2, 2), new Coordinate(2, 3))); - } }