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

#include <iostream> #include <ctime> #include <string> using namespace std; clas

ID: 3700361 • Letter: #

Question



#include <iostream> #include <ctime> #include <string> 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 < 3; i++ ) { for ( j = 0; j < 3; j++ ) { squares[i][j] = '0' + n; n++; } } } void Board::PB() { int i = 0; int j = 0; for ( i = 0; i < 3; i++ ) { for ( j = 0; j < 3; j++ ) { if ( j < 2 ) { cout << squares[i][j] << " | "; } else { cout << squares[i][j] << endl; } } } } void Board:: UT (char num, char Player) { int i = 0; int j = 0; bool OHCHIT = true; for( i = 0; i < 3; i++ ) { for( j = 0; j < 3; j++ ) { if(squares[i][j] == num) {
squares[i][j] = Player; OHCHIT = false; } } } if(OHCHIT == true) { cout << "Only mark spots that are open! "; } } bool Board:: CW (char Player, bool GameOver) { for(int i = 0; i < 3; i++) { if(squares[i][0] == squares[i][1] && squares[i][1] == squares[i][2]) GameOver = true; } for(int i = 0; i < 3; 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 << "Player " << Player << " wins! "; cout << "-----------------------" << endl; cout << "| NICE JOB " << Player << " | "; cout << "-----------------------" << endl << endl; } return GameOver; } bool Board:: CD(bool GameOver) { int n = 1; int i = 0; int j = 0; int counter = 0; for( i = 0; i < 3; i++ ) { for( j = 0; j < 3; j++ ) {
if(squares[i][j] == '0' + n) { counter++; } n++; } } if( counter < 1 ) { cout << "Draw "; 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 << "" << endl; cout << "-=Tic-Tac-Toe=- "; cout << "-------------"<< endl; Board TicTac; TicTac.BG(); TicTac.PB(); do { if( Player == 'X' ) { Player = 'O'; } else { Player = 'X'; } TicTac.PB(); cout << " Player "" << Player << "", it's your turn: "; cin >> num; cout << " "; TicTac.UT (num, Player); GameOver = TicTac.CW (Player, GameOver); GameOver = TicTac.CD(GameOver); if(GameOver == true) { cout << "Thank you for playing!"; finish = true; } } while(!finish);
}


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 I can use ASCII art to generate and display the 3x3x3 playing board. The program should randomly decide who 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 i 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 goes first computer or user. 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: X101.0 010 x 01 1-1

Explanation / Answer

This is Tic Tac Toe game which is played between two players, 'X' is sign of 1st player and 'O' is sign of 2nd player. Each player has its turn one after another. 1st Player marks 'X' and 2nd player marks 'O'. Winning target is align your sign in continuous manner

such as

In above cases player who has 'X' sign is winner. You have to align your sign continuous way either horizontally, vertically, or diagonally fashion.

The given code is developed on C++ using Object Oriented Way(OOPS Concept).

I have run you code on my machine and I got successful output

************ Output **************

-=Tic-Tac-Toe=-
-------------
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9

Player "X", it's your turn: 1

X | 2 | 3
4 | 5 | 6
7 | 8 | 9

Player "O", it's your turn: 5

X | 2 | 3
4 | O | 6
7 | 8 | 9

Player "X", it's your turn: 3

X | 2 | X
4 | O | 6
7 | 8 | 9

Player "O", it's your turn: 4

X | 2 | X
O | O | 6
7 | 8 | 9

Player "X", it's your turn: 2

Player X wins!

-----------------------
| NICE JOB X |
-----------------------

Thank you for playing!

X X X O O