|
|
@ -20,6 +20,7 @@ public class AIHard implements TicTacToeAI { |
|
|
|
@Override |
|
|
|
public void calculateNextMove() { |
|
|
|
int ownCharsInRow = 0; |
|
|
|
int ownCharsInCol = 0; |
|
|
|
int charsOfOpponentInRow = 0; |
|
|
|
int charsOfOpponentInCol = 0; |
|
|
|
int charsOfOpponentInDiag = 0; |
|
|
@ -27,16 +28,17 @@ public class AIHard implements TicTacToeAI { |
|
|
|
|
|
|
|
for (int i = 0; i < BOARD_SIZE; i++) { |
|
|
|
ownCharsInRow = countCharsInRow(i, AI_CHAR); |
|
|
|
ownCharsInCol = countCharsInCol(i, AI_CHAR); |
|
|
|
charsOfOpponentInRow = countCharsInRow(i, PLAYER_CHAR); |
|
|
|
charsOfOpponentInCol = countCharsInCol(i, PLAYER_CHAR); |
|
|
|
if (i < 2) { |
|
|
|
charsOfOpponentInDiag = countCharsInDiag(i, PLAYER_CHAR); |
|
|
|
} |
|
|
|
|
|
|
|
if (ownCharsInRow == BOARD_SIZE - 1) { |
|
|
|
if (ownCharsInRow == BOARD_SIZE - 1 || ownCharsInCol == BOARD_SIZE - 1) { |
|
|
|
for (int j = 0; j < BOARD_SIZE; j++) { |
|
|
|
if (board[i][j] == EMPTY_CHAR) { |
|
|
|
gl.setField(i, j, AI_CHAR); |
|
|
|
if (board[(ownCharsInRow == BOARD_SIZE - 1) ? i : j][(ownCharsInRow == BOARD_SIZE - 1) ? j : i] == EMPTY_CHAR) { |
|
|
|
gl.setField((ownCharsInRow == BOARD_SIZE - 1) ? i : j, (ownCharsInRow == BOARD_SIZE - 1) ? j : i, AI_CHAR); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|