diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index ffaa984..568de32 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -68,9 +68,15 @@ public class GameLogic { for (int i = this.board.length - 1, j = this.board.length - 1; i >= 0 ; i--, j--) { if (board[i][j] == player) countFields++; } + if(countFields == this.board.length) return finished = true; + countFields = 0; + + // check diagonal right + for (int i = this.board.length - 1, j = 0; i >= 0 ; i--, j++) { + if (board[i][j] == player) countFields++; + } if(countFields == this.board.length) return finished = true; - return finished; } diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index 216e02c..58abc9d 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -205,7 +205,11 @@ class GameLogicTest { Arguments.of("check diagonal left win for player 1", 'x', true, new char[][] {{'x', 'o', 'x'}, {'x', 'x', 'o'}, - {'o', 'o', 'x'}}) + {'o', 'o', 'x'}}), + Arguments.of("check diagonal right win for player 2", 'o', true, new char[][] + {{'x', 'x', 'o'}, + {'x', 'o', 'o'}, + {'o', 'x', 'x'}}) ); }