|
@ -21,6 +21,7 @@ public class AIHard implements TicTacToeAI { |
|
|
public void calculateNextMove() { |
|
|
public void calculateNextMove() { |
|
|
int ownCharsInRow = 0; |
|
|
int ownCharsInRow = 0; |
|
|
int ownCharsInCol = 0; |
|
|
int ownCharsInCol = 0; |
|
|
|
|
|
int ownCharsInDiag = 0; |
|
|
int charsOfOpponentInRow = 0; |
|
|
int charsOfOpponentInRow = 0; |
|
|
int charsOfOpponentInCol = 0; |
|
|
int charsOfOpponentInCol = 0; |
|
|
int charsOfOpponentInDiag = 0; |
|
|
int charsOfOpponentInDiag = 0; |
|
@ -32,14 +33,27 @@ public class AIHard implements TicTacToeAI { |
|
|
charsOfOpponentInRow = countCharsInRow(i, PLAYER_CHAR); |
|
|
charsOfOpponentInRow = countCharsInRow(i, PLAYER_CHAR); |
|
|
charsOfOpponentInCol = countCharsInCol(i, PLAYER_CHAR); |
|
|
charsOfOpponentInCol = countCharsInCol(i, PLAYER_CHAR); |
|
|
if (i < 2) { |
|
|
if (i < 2) { |
|
|
|
|
|
ownCharsInDiag = countCharsInDiag(i, AI_CHAR); |
|
|
charsOfOpponentInDiag = countCharsInDiag(i, PLAYER_CHAR); |
|
|
charsOfOpponentInDiag = countCharsInDiag(i, PLAYER_CHAR); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (ownCharsInRow == BOARD_SIZE - 1 || ownCharsInCol == BOARD_SIZE - 1) { |
|
|
if (ownCharsInRow == BOARD_SIZE - 1 || ownCharsInCol == BOARD_SIZE - 1) { |
|
|
for (int j = 0; j < BOARD_SIZE; j++) { |
|
|
for (int j = 0; j < BOARD_SIZE; j++) { |
|
|
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; |
|
|
|
|
|
|
|
|
if (ownCharsInRow == BOARD_SIZE - 1) { |
|
|
|
|
|
if (board[i][j] == EMPTY_CHAR) { |
|
|
|
|
|
gl.setField(i, j, AI_CHAR); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} else if (ownCharsInCol == BOARD_SIZE - 1) { |
|
|
|
|
|
if (board[j][i] == EMPTY_CHAR) { |
|
|
|
|
|
gl.setField(j, i, AI_CHAR); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} else if (ownCharsInDiag == BOARD_SIZE - 1) { |
|
|
|
|
|
if (board[j][(i == 1) ? i : BOARD_SIZE - 1 - j] == EMPTY_CHAR) { |
|
|
|
|
|
gl.setField(j, (i == 1) ? j : BOARD_SIZE - 1 - j, AI_CHAR); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|