Browse Source

4gewinnt: finished getFreePlaceMethod

4gewinnt
Steffen Helmke 3 years ago
committed by Lorenz Hohmann
parent
commit
caec8e73d7
  1. 8
      src/main/java/de/tims/viergewinnt/ai/Logic.java
  2. 8
      src/test/java/de/tims/viergewinnt/ai/LogicTest.java

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

@ -59,11 +59,11 @@ public class Logic {
}
public int getFreePlace(int column) {
if(getField(getBoardSize() - 1, column) == 0) {
return getBoardSize() - 1;
} else {
return getBoardSize() - 2;
int size = getBoardSize() - 1;
while(getField(size, column) != 0) {
size--;
}
return size;
}
public int playChip(int column) {

8
src/test/java/de/tims/viergewinnt/ai/LogicTest.java

@ -199,6 +199,14 @@ class LogicTest {
assertEquals(testObj.getBoardSize() - 2, testObj.getFreePlace(0));
}
@Test
void getFreePlaceTestWithAnyField() {
testObj.setField(1, testObj.getBoardSize() - 1, 0);
testObj.setField(1, testObj.getBoardSize() - 2, 0);
assertEquals(testObj.getBoardSize() - 3, testObj.getFreePlace(0));
}
private static Stream<Arguments> playfieldResults() {
int[][] playfield1 = {{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},

Loading…
Cancel
Save