Browse Source

tictactoe: added test case to check diagonal right win for player 2

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
94a38ff70e
  1. 8
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 6
      src/test/java/de/tims/tictactoe/GameLogicTest.java

8
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--) { for (int i = this.board.length - 1, j = this.board.length - 1; i >= 0 ; i--, j--) {
if (board[i][j] == player) countFields++; 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; if(countFields == this.board.length) return finished = true;
return finished; return finished;
} }

6
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[][] Arguments.of("check diagonal left win for player 1", 'x', true, new char[][]
{{'x', 'o', 'x'}, {{'x', 'o', 'x'},
{'x', 'x', 'o'}, {'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'}})
); );
} }

Loading…
Cancel
Save