1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
void solve_three_in_a_row(int board[MAX_SIZE][MAX_SIZE],
int size,
int row,
bool announce) {
for (int i = 0; i < size - 1; i++) {
if (board[row][i] == 1 && board[row][i + 1] == 1) {
if (i + 1 == size - 1 && i - 1 >= 0 && board[row][i - 1] == UNKNOWN) {
mark_square_as(board, size, row, i - 1, 2, announce);
}
else if (i == 0 && i + 2 <= size&&board[row][i + 2] == UNKNOWN) {
mark_square_as(board, size, row, i + 2, 2, announce);
}
else if (i - 1 >= 0 && i + 2 <= size&&board[row][i - 1] == UNKNOWN && board[row][i + 2] == UNKNOWN) {
mark_square_as(board, size, row, i - 1, 2, announce);
mark_square_as(board, size, row, i + 2, 2, announce);
}
}
else if (board[row][i] == 1 && board[row][i + 2] == 1 && board[row][i + 1] == UNKNOWN) {
mark_square_as(board, size, row, i + 1, 2, announce);
}
}
for (int i = 0; i < size - 1; i++) {
if (board[row][i] == 2 && board[row][i + 1] == 2) {
if (i + 1 == size - 1 && i - 1 >= 0 && board[row][i - 1] == UNKNOWN) {
mark_square_as(board, size, row, i - 1, 1, announce);
}
else if (i == 0 && i + 2 <= size&&board[row][i + 2] == UNKNOWN) {
mark_square_as(board, size, row, i + 2, 1, announce);
}
else if (i - 1 >= 0 && i + 2 <= size&&board[row][i - 1] == UNKNOWN && board[row][i + 2] == UNKNOWN) {
mark_square_as(board, size, row, i - 1, 1, announce);
mark_square_as(board, size, row, i + 2, 1, announce);
}
}
else if (board[row][i] == 2 && board[row][i + 2] == 2 && board[row][i + 1] == UNKNOWN) {
mark_square_as(board, size, row, i + 1, 1, announce);
}
}
}
|