|
|
@ -54,8 +54,24 @@ public class AIHard implements TicTacToeAI { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (board[1][1] == EMPTY_CHAR) { |
|
|
|
gl.setField(1, 1, AI_CHAR); |
|
|
|
if (board[BOARD_SIZE / 2][BOARD_SIZE / 2] == EMPTY_CHAR) { |
|
|
|
gl.setField(BOARD_SIZE / 2, BOARD_SIZE / 2, AI_CHAR); |
|
|
|
} else if (board[BOARD_SIZE / 2][BOARD_SIZE / 2] == AI_CHAR && (board[0][0] == AI_CHAR || board[0][BOARD_SIZE - 1] == AI_CHAR || board[BOARD_SIZE - 1][0] == AI_CHAR || board[BOARD_SIZE - 1][BOARD_SIZE - 1] == AI_CHAR)) { |
|
|
|
for (int i = BOARD_SIZE - 2; i > 0; i--) { |
|
|
|
for (int j = 0; j < BOARD_SIZE; j += BOARD_SIZE - 1) { |
|
|
|
for (int k = 1; k < BOARD_SIZE - 1; k++) { |
|
|
|
if (countCharsInRow(j, AI_CHAR) == i && countCharsInCol(k, AI_CHAR) == i && countCharsInRow(j, EMPTY_CHAR) == BOARD_SIZE -i && countCharsInCol(k, EMPTY_CHAR) == BOARD_SIZE - i) { |
|
|
|
gl.setField(j, k, AI_CHAR); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (countCharsInRow(k, AI_CHAR) == i && countCharsInCol(j, AI_CHAR) == i && countCharsInRow(k, EMPTY_CHAR) == BOARD_SIZE -i && countCharsInCol(j, EMPTY_CHAR) == BOARD_SIZE - i) { |
|
|
|
gl.setField(k, j, AI_CHAR); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
boolean emptyEdgeFound = false; |
|
|
|
int row = -1; |
|
|
|