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

In this assignment, you will make a Tic-Tac-Toe game in C++. You will be provide

ID: 3836510 • Letter: I

Question

In this assignment, you will make a Tic-Tac-Toe game in C++. You will be provided with starting code. Your task is to complete the tBoard object which controls the game mechanics. The customer (in this case your Professors) have already determined what the user interface should look like. You need to make a class that completes the game.

One of the goals of this project is to simulate how a team project would work in a company. You have no control over how the input/output with the user works. That has already been decided. You just need to figure out how to implement the back end to make design work.

----Have to code the tic.cpp (implementation) and then complete the tic.h (header) file which reads:

//You may add new methods (public or private) and new private attributes.

//You may NOT remove or change any methods given.

#ifndef _TIC_TAC_TOE_
#define _TIC_TAC_TOE_

#include
#include
#include
#include "symbol.h"
using namespace std;

class tBoard
{
   private:
       //You can pick your own data structure

   public:
       //Default Constructor
       //Makes a board with all blank spaces
       tBoard();
       //Makes a move on the board
       //X is the row and y is the column
       //m is the symbol to place (either X or O)
       //It returns true if the move was made
       //If the move is illegal, return false and do not change the table
       bool move(symbol m, int x, int y);
       //Returns true if the game is over
       //This could be because of a winner or because of a tie
       bool game_over();
       //Returns who won X or O.
       //If the game was a tie, return BLANK
       symbol winner();
};
//Overload the output operator
ostream & operator<<(ostream& os, const tBoard& myTable);

#endif

Can someone please help me get started with the header file and implementation/give guidelines?

--Both the code and the steps on how to do it would be appreciated--

Explanation / Answer

Here is an implementation that woudl do the job for you but you need to incorporate symbol data type wherever direct char is used.

class tBoard
{
private:
        //use a 3X3 char array to make the data structure
        char board[3][3];
//You can pick your own data structure
public:
//Default Constructor
//Makes a board with all blank spaces
tBoard()
{
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
            board[i][j] = ' ';
    }
}
//Makes a move on the board
//X is the row and y is the column
//m is the symbol to place (either X or O)
//It returns true if the move was made
//If the move is illegal, return false and do not change the table
bool move(symbol m, int x, int y)
{
    if(x<3 && x>=0 && y<3 && y>=0)
        {
            // I'm not having idea of the symbol data type used here. be used to change the data types
            // to fit your requirement
            //update the board only when the indexes match
            board[x][y] = m;
            return true;
        }
        else return false;
}
//Returns true if the game is over
//This could be because of a winner or because of a tie
bool game_over()
{
    //checking if any of the line - vertical or horizontal or diagonals is having the same symbol
   
    for(int i=0; i<3; i++)
    {
        // if all the three different cells are same then we have a winner
        if(board[i][0] == board[i][1] && board[i][1] == board[i][2])
            return true;
        if(board[0][i] == board[1][i] && board[1][i] == board[2][i])
            return true;
        if(board[0][0] == board[1][1] && board[1][1] == board[2][2])
            return true;
        if(board[0][2] == board[1][1] && board[1][1] == board[2][0])
            return true;
    }
    return false;
}
//Returns who won X or O.
//If the game was a tie, return BLANK
symbol winner()
{
    for(int i=0; i<3; i++)
    {
        // for x checking vertical, horizontal, diagonals
       
        if(board[i][0] == 'X' && board[i][0] == board[i][1] && board[i][1] == board[i][2])
            return 'X';
        if(board[0][i] == 'X' && board[0][i] == board[1][i] && board[1][i] == board[2][i])
            return 'X';
        if(board[0][0] == 'X' && board[0][0] == board[1][1] && board[1][1] == board[2][2])
            return 'X';
        if(board[0][2] == 'X' && board[0][2] == board[1][1] && board[1][1] == board[2][0])
            return 'X';
        // for o
        if(board[i][0] == 'O' && board[i][0] == board[i][1] && board[i][1] == board[i][2])
            return 'O';
        if(board[0][i] == 'O' && board[0][i] == board[1][i] && board[1][i] == board[2][i])
            return 'O';
        if(board[0][0] == 'O' && board[0][0] == board[1][1] && board[1][1] == board[2][2])
            return 'O';
        if(board[0][2] == 'O' && board[0][2] == board[1][1] && board[1][1] == board[2][0])
            return 'O';
    }
   
}
};
//Overload the output operator
ostream & operator<<(ostream& os, const tBoard& myTable)
{
       for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
            os<<board[i][j]<<" ";
        os<<endl;
    }
    return os;
}