Browse Source

add lastShot with Getter/Setter in ai-logic

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

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

@ -8,6 +8,8 @@ import de.tims.fleetstorm.matchfield.Matchfield;
public class Logic { public class Logic {
private Coordinate lastShot;
public Coordinate chooseField(Matchfield matchfield) { public Coordinate chooseField(Matchfield matchfield) {
ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>(); ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>();
for (int x = 0; x < Math.sqrt(matchfield.getSize()); x++) { for (int x = 0; x < Math.sqrt(matchfield.getSize()); x++) {
@ -35,4 +37,13 @@ public class Logic {
return out; return out;
} }
public void setLastShot(Coordinate coordinate, Matchfield matchfield) {
lastShot = matchfield.getField(coordinate);
}
public Coordinate getLastShot() {
return lastShot;
}
} }

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

@ -66,4 +66,21 @@ class LogicTest {
assertEquals(everySecondField, expectedResult); assertEquals(everySecondField, expectedResult);
} }
@Test
void testGetAndSetLastShot() {
Logic logic = new Logic();
Matchfield matchfield;
int size = 4;
matchfield = new Matchfield(size);
matchfield.createMatchfield();
Coordinate expectedResult = new Coordinate(2, 2);
logic.setLastShot(expectedResult, matchfield);
Coordinate result = logic.getLastShot();
assertEquals(result, expectedResult);
}
} }
Loading…
Cancel
Save