Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following function: const int MIN_SIZE = 2; const int MAX_SIZE = 8; co

ID: 3758340 • Letter: W

Question

Write the following function:

const int MIN_SIZE = 2;
const int MAX_SIZE = 8;

const int UNKNOWN = 0;
const int RED = 1;
const int BLUE = 2;

const char UNKNOWN_LETTER = '-';
const char RED_LETTER = 'X';
const char BLUE_LETTER = 'O';

const string UNKNOWN_STRING = "unknown";
const string RED_STRING = "X";
const string BLUE_STRING = "O";

/**
* Requires: size <= MAX_SIZE and size is a positive even integer,
*           0 <= row && row < size. The board must be valid.
* Modifies: board, cout
* Effects : This function writes the opposite color in UNKNOWN squares in row:
*           * on both ends of two consecutive tiles (example 1) in row, and
*           * in the middle between two tiles of the same color in row
*             (example 2)
*           If announce is true, prints out a message for each square
*           that is modified.
*
*           Example: ----              ----
*                     XX--   becomes    XXO-
*                     -XX-              OXXO
*                     --X-              --X-
*
*           Example: ----              ----
*                     X-X-   becomes    XOX-
*                     ----              ----
*                     --X-              --X-
* Note    : You MUST use mark_square_as() to assign a color to a square.
*           It will take care of printing out the appropriate message.
* Used In : solve()
*/
void solve_three_in_a_row(int board[MAX_SIZE][MAX_SIZE],
                          int size,
                          int row,
                          bool announce);

You are given:

void mark_square_as(int board[MAX_SIZE][MAX_SIZE],
                    int size,
                    int row,
                    int col,
                    int color,
                    bool announce) {
    if (announce) {
        cout << "marking (" << row + 1 << ", "
             << static_cast<char>(col + 'A') << ") as ";
        if (color == RED) {
            cout << RED_STRING;
        } else if (color == BLUE) {
            cout << BLUE_STRING;
        } else {
            cout << UNKNOWN_STRING;
        }
        cout << endl;
    }
    board[row][col] = color;
}

----------------------------------------------------------

I tried coding this myself and I am not sure why I am getting it wrong with mix match output. Below is my code.

int size,

int row,

bool announce) {

for(int j = 0; j < size; j++) {

if(board[row][j] == 1 && board[row][j+1] == 1) {

if(j - 1 >= 0 && j + 2 <= size) {

mark_square_as(board, size, row, j-1, 2, announce);

mark_square_as(board, size, row, j+2, 2, announce);

}

else if(j + 1 == size && j - 1 >= 0) {

mark_square_as(board, size, row, j-1, 2, announce);

}

else if(j == 0 && j + 2 <= size){

mark_square_as(board, size, row, j+2, 2, announce);

}

}

else if(board[row][j] == 1 && board[row][j+2] == 1) {

mark_square_as(board, size, row, j+1, 2, announce);

}

}

for(int j = 0; j < size; j++) {

if(board[row][j] == 2 && board[row][j+1] == 2) {

if(j - 1 >= 0 && j + 2 <= size) {

mark_square_as(board, size, row, j-1, 1, announce);

mark_square_as(board, size, row, j+2, 1, announce);

}

else if(j + 1 == size && j - 1 >= 0) {

mark_square_as(board, size, row, j-1, 1, announce);

}

else if(j == 0 && j + 2 <= size){

mark_square_as(board, size, row, j+2, 1, announce);

}

}

else if(board[row][j] == 2 && board[row][j+2] == 2) {

mark_square_as(board, size, row, j+1, 1, announce);

}

}

}

Explanation / Answer

int row, bool announce) { for (int i = 0; i = 0 && board[row][i - 1] == UNKNOWN) { mark_square_as(board, size, row, i - 1, 2, announce); } else if (i == 0 && i + 2 = 0 && i + 2