Browse Source

tictactoe: countCharsInRow counts number of given char in specific row

tictactoe
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
9029de6c12
  1. 8
      src/main/java/de/tims/tictactoe/ai/AIHard.java
  2. 7
      src/test/java/de/tims/tictactoe/ai/AIHardTest.java

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

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

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

@ -79,8 +79,11 @@ class AIHardTest {
private static Stream<Arguments> testCasesForCountCharsInRow() {
return Stream.of(Arguments.of("EmptyFieldReturns0",
new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} },
0, 'o', 0));
new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} },
0, 'o', 0),
Arguments.of("TwoCharsInRowReturnsTwo",
new char[][] { {'-', '-', '-'}, {'o', 'o', '-'}, {'-', '-', '-'} },
1, 'o', 2));
}
}
Loading…
Cancel
Save