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

Write a program where a user plays a games of Tic Tac Toe against the computer,

ID: 3662439 • Letter: W

Question

Write a program where a user plays a games of Tic Tac Toe against the computer, and tries to remains undefeated for as long as possible. The program should display the board before every turn The user enters coordinates to place their piece The game should keep prompting for coordinates if the space is already occupied or it is a non-negative, invalid input If the user enters a negative number they quit and the computer wins The computer then randomly selects an empty space and places their piece If there are no available spaces ("CAT") then the game is over but the player does not lose If the player wins the computer demands a rematch. This will happen until the player loses or quits. Once the user loses they are asked to enter their name so it can be recorded to a high score file. Then the file's contents are displayed in game. The user can then choose to enter the tournament again or quit.

Explanation / Answer

#include <iostream.h>
#define X 'X'
#define O 'O'
#define yes 1
#define no 0
//intialise variables
int check (char[][3], int, int);
void reckoner (char a[][3], char turn);
void progress (char a[][3]);
void main()
{
char a[3][3];//declered possitions right and play
int row,col,right=yes,turn,play=yes,counter=0,r,c,d;
for (row=0; row<3; row++)
{
for (col=0; col<3; col++)
{
a[row][col]=' ';
}
}
cout << " Game TIC TAC TOE ";
//start the game by pick the option
cout << " please pick the row then the column. ";
progress(a);
do
{
do
{
turn=X;
cout << "Row: ";
cin >> row;
cout << "Column: ";
cin >> col;
row--;
col--;
a[row][col];
right=check (a,row,col);
if (!right)
}while (!right);
a[row][col]=X;
counter++;
play=winlose(a, play);
turn=O;
if (!play)
{
progress(a);
cout << " win " << endl;
cin >> play;
play=go_on(play);
if (!play)
break;
}
if (play)
{
reckoner (a, turn);
play=winlose(a,play);
}
if (play==2)
{
cout << " lost your play ,how failing >.> " << endl;
cout << "Play again " << "1.yes " << "0.no " << endl;
cin >> play;
play=go_on(play);
if(!play)
break;
}
if (counter==5 && play)
{
cout << " it is a tie " << endl;
cin >> play;
play=go_on(play);
if(!play)
break;
}
}while (play);
}

int go_on (int play)
{
if (play)
{
main();
{
return no;

int check (char a[][3], int row, int col)
return no;
}

int winlose (char a[][3], int play)
{
int row, col, r, c, d, ro, co, dO;
for (row=0; row<3; row++)
{
r=0;
c=0;
d=0;
ro=0;
co=0;
dO=0;
for (col=0; col<3; col++)
{
if(a[row][col]==X)
r++;
if(a[row][col]==O)
ro++;
if(a[col][row]==X)
c++;
if(a[col][row]==O)
co++;
if(a[col][col]==X)
d++;
if(a[col][col]==O)
dO++;
if (ro==3 || co==3 || dO==3)
play=2;

}
}
if (a[0][2]==X && a[1][1]==X && a[2][0]==X)
d=3;
if (a[0][2]==O && a[1][1]==O && a[2][0]==O)
play=2;
if (r==3 || c==3 || d==3)
play=no;
return play;
}


void reckoner (char a[][3], char turn)
{
int i,j,play;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
if (a[i][j]==' ' && turn==O)
{
a[i][j]=O;
turn=X;
}
progress(a);
}
void progress (char a[][3])//board design
{
cout << " _________________ ";
cout << "| | | | ";
cout << "| " << a[0][0] << " | " << a[0][1] << " | " << a[0][2] <<
" | ";
cout << "|_____|_____|_____| ";
cout << "| | | | ";
cout << "| " << a[1][0] << " | " << a[1][1] << " | " << a[1][2] <<
" | ";
cout << "|_____|_____|_____| ";
cout << "| | | | ";
cout << "| " << a[2][0] << " | " << a[2][1] << " | " << a[2][2] <<
" | ";
cout << "|_____|_____|_____| ";

}

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