From 0387c76c9733edf6749bdfd32bf3831d6341a64a Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Fri, 14 Jan 2022 11:54:05 +0100 Subject: [PATCH] add clearBelow --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 9 +++++++++ .../java/de/tims/fleetstorm/ai/LogicTest.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index 2db3212..64f5e6d 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -13,6 +13,7 @@ public class Logic { public Coordinate target; private boolean foundShip = false; public boolean clearedAbove = false; + public boolean clearedBelow = false; public Coordinate chooseField() { ArrayList possibleFields = new ArrayList(); @@ -95,4 +96,12 @@ public class Logic { } + public void clearBelow(Coordinate shot) { + target = matchfield.getBelow(shot); + + if (target.getState() == Coordinate.EMPTY) { + clearedBelow = true; + } + + } } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 76f4759..0267c1a 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -141,4 +141,21 @@ class LogicTest { assertEquals(logic.clearedAbove, true); } + @Test + void testClearBelow() { + Logic logic = new Logic(); + Matchfield matchfield; + Coordinate shot = new Coordinate(2, 2); + int size = 4; + matchfield = new Matchfield(size); + matchfield.createMatchfield(); + logic.setMatchfield(matchfield); + logic.setLastShot(shot); + matchfield.getField(shot).setState(Coordinate.EMPTY); + + logic.clearBelow(shot); + + assertEquals(logic.clearedBelow, true); + } + }