From 6b53586a1ba79120b32d562c52544a1419b5db69 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Fri, 14 Jan 2022 12:04:37 +0100 Subject: [PATCH] add clearleft --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 10 ++++++++++ .../java/de/tims/fleetstorm/ai/LogicTest.java | 16 ++++++++++++++++ 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 ad891cc..6a93698 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -15,6 +15,7 @@ public class Logic { public boolean clearedAbove = false; public boolean clearedBelow = false; public boolean clearedRight = false; + public boolean clearedLeft = false; public Coordinate chooseField() { ArrayList possibleFields = new ArrayList(); @@ -114,4 +115,13 @@ public class Logic { } } + + public void clearLeft(Coordinate shot) { + target = matchfield.getLeft(shot); + + if (target.getState() == Coordinate.EMPTY) { + clearedLeft = true; + } + + } } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 79a8ab8..622eebb 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -175,4 +175,20 @@ class LogicTest { assertEquals(logic.clearedRight, true); } + @Test + void testClearLeft() { + 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.clearLeft(shot); + + assertEquals(logic.clearedLeft, true); + } }