Browse Source

add clearleft

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

10
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<Coordinate> possibleFields = new ArrayList<Coordinate>();
@ -114,4 +115,13 @@ public class Logic {
}
}
public void clearLeft(Coordinate shot) {
target = matchfield.getLeft(shot);
if (target.getState() == Coordinate.EMPTY) {
clearedLeft = true;
}
}
}

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