Browse Source

Fix: chooseField makes way more sense now

Max Wenzel 3 years ago
parent
commit
7759a2ff28
  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 (!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;
}

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

@ -288,10 +288,13 @@ class LogicTest {
matchfield.setState(expectedResult, Coordinate.HIT);
logic.setMatchfield(matchfield);
logic.setLastShot(center);
logic.setTarget(empty);
logic.setTarget(center);
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);
}
}
Loading…
Cancel
Save