From bf1f6b2ac306d022d6188da4ebb023c910d9beff Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Thu, 13 Jan 2022 14:56:55 +0100 Subject: [PATCH] Refactoring: getEverySecondField() doesn't need param matchfield anymore --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 8 ++++---- src/test/java/de/tims/fleetstorm/ai/LogicTest.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index 668984b..8acdc8d 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -26,12 +26,12 @@ public class Logic { return possibleFields.get(randy.nextInt(possibleFields.size())); } - public ArrayList getEverySecondField(Matchfield matchfield) { + public ArrayList getEverySecondField() { ArrayList out = new ArrayList(); - 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)) { - out.add(matchfield.getField(x, y)); + out.add(this.matchfield.getField(x, y)); } } } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 440710d..7257ccf 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -53,8 +53,9 @@ class LogicTest { int size = 4; matchfield = new Matchfield(size); matchfield.createMatchfield(); + logic.setMatchfield(matchfield); - ArrayList everySecondField = logic.getEverySecondField(matchfield); + ArrayList everySecondField = logic.getEverySecondField(); ArrayList expectedResult = new ArrayList(); expectedResult.add(new Coordinate(0, 0));