From 794f4bbb516ad731f5d43b34cd749ff5f0dbfd27 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Fri, 14 Jan 2022 11:43:18 +0100 Subject: [PATCH] add clearAbove --- .../java/de/tims/fleetstorm/ai/Logic.java | 20 +++++++++++++++++++ .../java/de/tims/fleetstorm/ai/LogicTest.java | 17 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index e6838d4..2db3212 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -10,7 +10,9 @@ public class Logic { private Matchfield matchfield; private Coordinate lastShot; + public Coordinate target; private boolean foundShip = false; + public boolean clearedAbove = false; public Coordinate chooseField() { ArrayList possibleFields = new ArrayList(); @@ -75,4 +77,22 @@ public class Logic { return this.foundShip; } + public void checkAround(Coordinate coordinate) { + // TODO Auto-generated method stub + + } + + public void clearAbove(Coordinate shot) { + target = matchfield.getAbove(shot); + + if (target.getState() == Coordinate.EMPTY) { + clearedAbove = true; + } + } + + private void shot() { + // TODO Auto-generated method stub + + } + } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index c0b7f08..76f4759 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -124,4 +124,21 @@ class LogicTest { assertEquals(logic.getFoundShip(), true); } + @Test + void testClearAbove() { + 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.clearAbove(shot); + + assertEquals(logic.clearedAbove, true); + } + }