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

Connect Four: Write a C++ program that plays the game of connect four. To see ho

ID: 3778675 • Letter: C

Question

Connect Four:

Write a C++ program that plays the game of connect four. To see how to play the traditional 2-person game, visit page 2 of these instructions: http://www.hasbro.com/common/documents/dad2614d1c4311ddbd0b0800200c9a66/1EF 6874419B9F36910222EB9858E8CB8.pdf

Connect Four has a 6 x 7 board, and the goal of the game is to connect four pieces together horizontally, diagonally, or vertically. Your program will be a little different in that you can have a board of any size, rather than a 6x7 board, but you will always connect 4 pieces in this game. You need to make sure you handle inappropriate data, i.e. nonpositive integers, and ask the user again for the correct input. You must continue to play the game, until the user no longer wants to play. A requirement for this program is that your functions are 15 lines or less, and you must not have any global variables. In addition, the command-line argument option and value pair can come in any order, and if one of the options or values are not valid, then you need to print a message an exit. Also, you cannot have any memory leaks in your program!!!

(10 pts) Extra Credit: Connect Any In this game, you will get the number of pieces you want to connect in a row, which can be 2-any number. This determines how many pieces have to be in a row horizontally, vertically, or diagonally to win! This will be an extra command line argument with a –p option before the value. ./connect_four –r 6 –c 7 –p 4

Explanation / Answer

void Initialize(char Slots[ROWS][COLUMNS])

{

    // Sets up Game Board

    for (int r = 0; r < ROWS; r++)

        for (int c = 0; c < COLUMNS; c++)

            Slots[r][c] = EMPTY;

}

//-------------------------------------------

void PrintBoard (const char GameBoard[ROWS][COLUMNS])

{

    cout << " 0   1   2   3   4   5 " << endl;

    cout << "|-----------------------|" << endl;

    for (int r = 0; r < ROWS ; r++)

    {

        cout << "| ";

        for (int c = 0; c < COLUMNS; c++)

        {

               cout << GameBoard[r][c];

            cout << " | ";

        }

        cout << endl << "|-----------------------|" << endl;

    }

}

//-------------------------------------------

int main ()

{

// Declare Variables       

char GameBoard[ROWS][COLUMNS]; // Array for tracking the game

    // Initialize the board

    Initialize(GameBoard);

    // Display Game Board

    PrintBoard(GameBoard);

   

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote