diff --git a/src/main/java/de/tims/tictactoe/ai/AIHard.java b/src/main/java/de/tims/tictactoe/ai/AIHard.java index ac70681..56ff489 100644 --- a/src/main/java/de/tims/tictactoe/ai/AIHard.java +++ b/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) { - 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; } } diff --git a/src/test/java/de/tims/tictactoe/ai/AIHardTest.java b/src/test/java/de/tims/tictactoe/ai/AIHardTest.java index 76a81f5..f764772 100644 --- a/src/test/java/de/tims/tictactoe/ai/AIHardTest.java +++ b/src/test/java/de/tims/tictactoe/ai/AIHardTest.java @@ -100,7 +100,10 @@ class AIHardTest { private static Stream testCasesForCountCharsInCol() { return Stream.of(Arguments.of("EmptyFieldReturns0", new char[][] { {'-', '-', '-'}, {'-', '-', '-'}, {'-', '-', '-'} }, - 0, 'o', 0)); + 0, 'o', 0), + Arguments.of("TwoCharsInRowReturnsTwo", + new char[][] { {'-', '-', '-'}, {'o', 'o', '-'}, {'-', '-', '-'} }, + 1, 'o', 1)); } }