QuestionQuestion

Using C++

Write a class called GBoard that represents the board for a game that is like tic-tac-toe, but on a larger scale. Instead of a 3x3 board, it is played on a 15x15 board, and instead of 3 in a row, each player is trying to get 5 in row.

The class should have two data members - a 2D array of char that represents the board, and an enum variable called gameState that holds one of the four following values: X_WON, O_WON, DRAW, or UNFINISHED - use an enum for this, not strings (the enum definition should go in GBoard.hpp, before the class, not inside it).

It should have a default constructor that initializes all elements of the array to being empty (you can use whatever character you want to represent that a square is empty), and initializes the gameState to UNFINISHED.

It should have a method called getGameState that returns the value of gameState.

It should have a method called makeMove that takes as parameters an int for the row, an int for the column, and a char for the player. The row and column will be in the range 0-14. The player will be either 'x' or 'o'. This method should return false if the square is already occupied or the game had already finished. Otherwise it should add the move to the board, update the gameState, and return true. Be careful to not access your array out of bounds - including in the condition of an if statement or loop.

It's not required, but you'll probably find it useful for testing and debugging to have a method that prints out the board.

Whether you think of the array indices as being [row][column] or [column][row] doesn't matter as long as you're consistent.

Your class only represents the board, it doesn't actually allow two players to play the game. Other code (that you don't have to write) would use your Board class to make that happen.

The files must be named: GBoard.hpp and GBoard.cpp

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

bool GBoard::makeMove(int row, int col, char sign)
{
    bool result = false;
    /************************
    * Check if arguments are
    * valid
    * *********************/
    if ((row < SIZE) && (col < SIZE) && ((sign == 'x') || (sign == 'o')) && (board[row][col] == EMPTY) && (gameState == UNFINISHED))
    {
       /************************
       * Insert the new field
       * value
       * *********************/
       board[row][col] = sign;
      
       /************************
       * Check if the new field
       * is a member of winning
       * series in north-south
       * direction
       * *********************/
       int rmin = std::max(row - SERIES + 1, 0); // minimum row index that can be a member
       int rmax = std::min(row + SERIES, SIZE); // maximum row index that can be a member
       int rstart = rmin; // start from minimum and check the series
       bool win = false;
       while ((!win) && (rstart < (rmax - SERIES + 1)))
       {
            win = true;
            int r = 0;
            while ((win) && (r < SERIES))
            {
                win &= (board[rstart + r][col] == sign);
                r++;
            }
            rstart++;
       }

       /************************
       * Check if the new field
       * is a member of winning
       * series in west-east
       * direction
       * *********************/
       int cmin = std::max(col - SERIES + 1, 0);
       int cmax = std::min(col + SERIES, SIZE);
       int cstart = cmin;
       while ((!win) && (cstart < (cmax - SERIES + 1)))
       {
            win = true;
            int c = 0;
            while ((win) && (c < SERIES))
            {
                win &= (board[row][cstart + c] == sign);
                c++;
            }
            cstart++;
       }...
$50.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats