Browse Source

4gewinnt: testForWin column1 player1 check

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

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

@ -2,6 +2,15 @@ package de.tims.viergewinnt.ai;
public class Logic { public class Logic {
public boolean testForWin(int[][] playfield, int player) { public boolean testForWin(int[][] playfield, int player) {
int chain = 0;
for(int i = 0; i < playfield.length; i++) {
if(playfield[i][0] == player) {
chain++;
} else {
chain = 0;
}
if(chain == 4) return true;
}
return false; return false;
} }
} }

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

@ -29,8 +29,15 @@ class LogicTest {
} }
private static Stream<Arguments> playfieldResults() { private static Stream<Arguments> playfieldResults() {
int[][] playfield1 = {{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0}};
return Stream.of( return Stream.of(
Arguments.of("emptyField", new int[6][6], 1, false)
Arguments.of("emptyField", new int[6][6], 1, false),
Arguments.of("4 in 1st column player1", playfield1, 1, true)
); );
} }

Loading…
Cancel
Save