Browse Source

add clearRight

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

10
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<Coordinate> possibleFields = new ArrayList<Coordinate>();
@ -104,4 +105,13 @@ public class Logic {
}
}
public void clearRight(Coordinate shot) {
target = matchfield.getRight(shot);
if (target.getState() == Coordinate.EMPTY) {
clearedRight = true;
}
}
}

17
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);
}
}
Loading…
Cancel
Save