diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index 64f5e6d..ad891cc 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -14,6 +14,7 @@ public class Logic { private boolean foundShip = false; public boolean clearedAbove = false; public boolean clearedBelow = false; + public boolean clearedRight = false; public Coordinate chooseField() { ArrayList possibleFields = new ArrayList(); @@ -104,4 +105,13 @@ public class Logic { } } + + public void clearRight(Coordinate shot) { + target = matchfield.getRight(shot); + + if (target.getState() == Coordinate.EMPTY) { + clearedRight = true; + } + + } } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 0267c1a..79a8ab8 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -158,4 +158,21 @@ class LogicTest { assertEquals(logic.clearedBelow, true); } + @Test + void testClearRight() { + 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.clearRight(shot); + + assertEquals(logic.clearedRight, true); + } + }