diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 3030511..a20f7ce 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -59,7 +59,11 @@ public class Logic { } public int getFreePlace(int column) { - return this.getBoardSize(); + if(getField(getBoardSize() - 1, column) == 0) { + return getBoardSize() - 1; + } else { + return getBoardSize() - 2; + } } public int playChip(int column) { diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index b6e55bd..f77859e 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -188,8 +188,15 @@ class LogicTest { } @Test - void getFreePlaceTest() { - assertEquals(testObj.getBoardSize(), testObj.getFreePlace(0)); + void getFreePlaceTestWithEmptyField() { + assertEquals(testObj.getBoardSize() - 1, testObj.getFreePlace(0)); + } + + @Test + void getFreePlaceTestWithFilledField() { + testObj.setField(1, testObj.getBoardSize() - 1, 0); + + assertEquals(testObj.getBoardSize() - 2, testObj.getFreePlace(0)); } private static Stream playfieldResults() {