Browse Source

tictactoe: countCharsInCol counts number of given char in specific col

tictactoe
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
36b8cdfcac
  1. 9
      src/main/java/de/tims/tictactoe/ai/AIHard.java
  2. 5
      src/test/java/de/tims/tictactoe/ai/AIHardTest.java

9
src/main/java/de/tims/tictactoe/ai/AIHard.java

@ -68,6 +68,13 @@ public class AIHard implements TicTacToeAI {
} }
public int countCharsInCol(int index, char charToCount) { public int countCharsInCol(int index, char charToCount) {
return 0;
int count = 0;
char[][] board = gl.getBoard();
for (int i = 0; i < BOARD_SIZE; i++) {
count += (board[i][index] == charToCount) ? 1 : 0;
}
return count;
} }
} }

5
src/test/java/de/tims/tictactoe/ai/AIHardTest.java

@ -100,7 +100,10 @@ class AIHardTest {
private static Stream<Arguments> testCasesForCountCharsInCol() { private static Stream<Arguments> testCasesForCountCharsInCol() {
return Stream.of(Arguments.of("EmptyFieldReturns0", return Stream.of(Arguments.of("EmptyFieldReturns0",
new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} }, new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} },
0, 'o', 0));
0, 'o', 0),
Arguments.of("TwoCharsInRowReturnsTwo",
new char[][] { {'-', '-', '-'}, {'o', 'o', '-'}, {'-', '-', '-'} },
1, 'o', 1));
} }
} }
Loading…
Cancel
Save