From acdb95b9d6098e0c4d1bd5dd8bfd4bfb606afc9c Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Thu, 13 Jan 2022 13:19:17 +0100 Subject: [PATCH] add lastShot with Getter/Setter in ai-logic --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 11 +++++++++++ .../java/de/tims/fleetstorm/ai/LogicTest.java | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index ddbc555..ca0e69e 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -8,6 +8,8 @@ import de.tims.fleetstorm.matchfield.Matchfield; public class Logic { + private Coordinate lastShot; + public Coordinate chooseField(Matchfield matchfield) { ArrayList possibleFields = new ArrayList(); for (int x = 0; x < Math.sqrt(matchfield.getSize()); x++) { @@ -35,4 +37,13 @@ public class Logic { return out; } + public void setLastShot(Coordinate coordinate, Matchfield matchfield) { + lastShot = matchfield.getField(coordinate); + + } + + public Coordinate getLastShot() { + return lastShot; + } + } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 5eb55c0..dd4f8c3 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -66,4 +66,21 @@ class LogicTest { assertEquals(everySecondField, expectedResult); } + + @Test + void testGetAndSetLastShot() { + Logic logic = new Logic(); + Matchfield matchfield; + int size = 4; + matchfield = new Matchfield(size); + matchfield.createMatchfield(); + + Coordinate expectedResult = new Coordinate(2, 2); + logic.setLastShot(expectedResult, matchfield); + Coordinate result = logic.getLastShot(); + + assertEquals(result, expectedResult); + + } + }