Browse Source

Refactoring: Implements Coordinate into ai-logic

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

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

@ -8,12 +8,12 @@ import de.tims.fleetstorm.matchfield.Matchfield;
public class Logic {
public int[] chooseField(Matchfield matchfield) {
ArrayList<int[]> possibleFields = new ArrayList<int[]>();
public Coordinate chooseField(Matchfield matchfield) {
ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>();
for (int x = 0; x < Math.sqrt(matchfield.getSize()); x++) {
for (int y = 0; y < Math.sqrt(matchfield.getSize()); y++) {
if (matchfield.getState(x, y) == Coordinate.EMPTY || matchfield.getState(x, y) == Coordinate.SHIP) {
possibleFields.add(new int[] { x, y });
possibleFields.add(new Coordinate(x, y));
}
}
}

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

@ -16,7 +16,7 @@ class LogicTest {
@Test
void testFieldIsNotNull() {
matchfield.createMatchfield();
int[] calcResult = logic.chooseField(matchfield);
Coordinate calcResult = logic.chooseField(matchfield);
assertNotNull(calcResult);
}
@ -30,8 +30,8 @@ class LogicTest {
}
// matchfield.setState(0, 0, Matchfield.EMPTY);
int[] choosenField = logic.chooseField(matchfield);
int calcState = matchfield.getState(choosenField[0], choosenField[1]);
Coordinate choosenField = logic.chooseField(matchfield);
int calcState = matchfield.getState(choosenField.getX(), choosenField.getY());
assertNotEquals(calcState, Coordinate.SHOT);
}
}
Loading…
Cancel
Save