Browse Source

Refactoring: getEverySecondField() doesn't need param matchfield anymore

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

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

@ -26,12 +26,12 @@ public class Logic {
return possibleFields.get(randy.nextInt(possibleFields.size())); return possibleFields.get(randy.nextInt(possibleFields.size()));
} }
public ArrayList<Coordinate> getEverySecondField(Matchfield matchfield) {
public ArrayList<Coordinate> getEverySecondField() {
ArrayList<Coordinate> out = new ArrayList<Coordinate>(); ArrayList<Coordinate> out = new ArrayList<Coordinate>();
for (int x = 0; x < Math.sqrt(matchfield.getSize()); x++) {
for (int y = 0; y < Math.sqrt(matchfield.getSize()); y++) {
for (int x = 0; x < Math.sqrt(this.matchfield.getSize()); x++) {
for (int y = 0; y < Math.sqrt(this.matchfield.getSize()); y++) {
if ((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1)) { if ((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1)) {
out.add(matchfield.getField(x, y));
out.add(this.matchfield.getField(x, y));
} }
} }
} }

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

@ -53,8 +53,9 @@ class LogicTest {
int size = 4; int size = 4;
matchfield = new Matchfield(size); matchfield = new Matchfield(size);
matchfield.createMatchfield(); matchfield.createMatchfield();
logic.setMatchfield(matchfield);
ArrayList<Coordinate> everySecondField = logic.getEverySecondField(matchfield);
ArrayList<Coordinate> everySecondField = logic.getEverySecondField();
ArrayList<Coordinate> expectedResult = new ArrayList<Coordinate>(); ArrayList<Coordinate> expectedResult = new ArrayList<Coordinate>();
expectedResult.add(new Coordinate(0, 0)); expectedResult.add(new Coordinate(0, 0));

Loading…
Cancel
Save