Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Based on the following code, please help me with the additions called for Im attached picture. Thank you #include #include #include using namespace std; class

Based on the following code, please help me with the additions called for Im attached picture. Thank you
#include
#include
#include
using namespace std;
class Board
{
private:
char squares[3][3];
public:
Board() {}
void PB();
void BG();
void UT (char num, char Player);
bool CW (char Player, bool gameOver);
bool CD(bool gameOver);
};
void Board::BG()
{
int n = 1;
int i = 0;
int j = 0;
for ( i = 0; i
{
for ( j = 0; j
{
squares[i][j] = '0' + n;
n++;
}
}
}
void Board::PB()
{
int i = 0;
int j = 0;
for ( i = 0; i
{
for ( j = 0; j
{
if ( j
{
cout
}
else
{
cout
}
}
}
}
void Board:: UT (char num, char Player)
{
int i = 0;
int j = 0;
bool OHCHIT = true;
for( i = 0; i
{
for( j = 0; j
{
if(squares[i][j] == num)
{
squares[i][j] = Player;
OHCHIT = false;
}
}
}
if(OHCHIT == true) { cout
}
bool Board:: CW (char Player, bool GameOver)
{
for(int i = 0; i
{
if(squares[i][0] == squares[i][1] && squares[i][1] ==
squares[i][2]) GameOver = true;
}
for(int i = 0; i
{
if(squares[0][i] == squares[1][i] && squares[1][i] ==
squares[2][i]) GameOver = true;
}
if(squares[0][0] == squares[1][1] && squares[1][1] == squares[2][2])
{
GameOver = true;
}
if(squares[0][2] == squares[1][1] && squares[1][1] == squares[2][0])
{
GameOver = true;
}
if(GameOver == true)
{
cout
cout
cout
cout
}
return GameOver;
}
bool Board:: CD(bool GameOver)
{
int n = 1;
int i = 0;
int j = 0;
int counter = 0;
for( i = 0; i
{
for( j = 0; j
{
if(squares[i][j] == '0' + n)
{
counter++;
}
n++;
}
}
if( counter
{
cout
GameOver = true;
}
return GameOver;
}
int main()
{
bool finish = false, GameOver = false,isValid;
char Player = 'O', num;
int number;
srand(time(NULL));
number = rand()%2;
if(number == 0)
Player = 'X';
else
Player = 'O';
cout
cout
cout
Board TicTac;
TicTac.BG();
TicTac.PB();
do
{
if( Player == 'X' )
{
Player = 'O';
}
else
{
Player = 'X';
}
TicTac.PB();
cout
cin >> num;
cout
TicTac.UT (num, Player);
GameOver = TicTac.CW (Player, GameOver);
GameOver = TicTac.CD(GameOver);
if(GameOver == true)
{
cout
finish = true;
}
} while(!finish);
}
image text in transcribed
Programming assignment (100 pts): In the C++ programming language write a program capable of playing 3D Tic-Tac-Toe against the user. Your program should use OOP concepts in its design. Use Inheritance to create a derived class from your can use ASCII art to generate and display the 3x3x3 playing board. The program should randomly decide who goes first computer or user user if an illegal move was made (cell already occupied). The program should also keep the score and announce if one of the players wins or if a draw is achieved. While it is desirable for your program to play a strong game, this is not an Artificial Intelligence course so if your program does not play at a world champion level you will not be penalized for it. Lab #9 Tic-Tac-Toe class. You Your program should know and inform the The object of a 3D-TTT is to get as many 3-in-a-row as possible. You win just like in traditional TTT, except you can also win by getting 3-in-a-raw down each board. Imagine the boards as placed on top of each other Blank Board Game in Progress X10_1.0 xIxX 010 x 0-1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions