Browse Source

Fix: chooseField makes way more sense now

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
1fd251655c
  1. 15
      src/main/java/de/tims/fleetstorm/ai/Logic.java
  2. 7
      src/test/java/de/tims/fleetstorm/ai/LogicTest.java

15
src/main/java/de/tims/fleetstorm/ai/Logic.java

@ -30,12 +30,19 @@ public class Logic {
if (foundShip) { if (foundShip) {
if (!clearedAbove) { if (!clearedAbove) {
target = matchfield.getAbove(target);
if (target.getState() == Coordinate.EMPTY) {
clearedAbove = true;
}
return target;
}
if (target.equals(lastShot)) {
target = lastShot;
target = matchfield.getAbove(lastShot);
} else {
target = matchfield.getBelow(lastShot);
if (!clearedBelow) {
target = matchfield.getBelow(target);
if (target.getState() == Coordinate.EMPTY) {
clearedBelow = true;
} }
return target; return target;
} }

7
src/test/java/de/tims/fleetstorm/ai/LogicTest.java

@ -288,10 +288,13 @@ class LogicTest {
matchfield.setState(expectedResult, Coordinate.HIT); matchfield.setState(expectedResult, Coordinate.HIT);
logic.setMatchfield(matchfield); logic.setMatchfield(matchfield);
logic.setLastShot(center); logic.setLastShot(center);
logic.setTarget(empty);
logic.setTarget(center);
logic.setFoundShip(true); logic.setFoundShip(true);
Coordinate result = logic.chooseField(logic.getEverySecondField());
logic.chooseField(logic.getEverySecondField()); // first Shot
Coordinate result = logic.chooseField(logic.getEverySecondField()); // second Shot
assertEquals(result, expectedResult); assertEquals(result, expectedResult);
} }
} }
Loading…
Cancel
Save