TIC-TAC-TOE Your task is to develop a tic-tac-toe game. There are two options for you to choose from. One option is a tic-tac-toe…

TIC-TAC-TOE

Your task is to develop a tic-tac-toe game. There are two options for you to choose from. One option is a tic-tac-toe game where two humans may play. The second option is one where a human may play against the computer. Option one is worth less points (90% of total points) than option two (100% of total points).

Don't use plagiarized sources. Get Your Custom Essay on
TIC-TAC-TOE Your task is to develop a tic-tac-toe game. There are two options for you to choose from. One option is a tic-tac-toe…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

PROGRAM REQUIREMENTS

The program prompts users for their names and ensures (validates) them; users are allowed to enter a single username consisting of alpha chars ONLY.

Use one-dimensional arrays to keep track of the game:

Human moves in the case of option one.

Computer moves as well in the case of option two.

Use functions to pass arrays and implement other program requirements such as input validation, checking to ensure that places selected by users are available on the “game board”.

Validate user input at every opportunity.

Do not allow number entries less than 0 or entries greater than 8 (in the case you are using numbers 0-8 on the “grid”.

Do not allow number entries less than 0 or entries greater than 8 (in the case you are using numbers 1-9 on the “grid”.

Do not allow non-numeric entries.

If your program crashes due to an invalid entry made by the user, then you will not pass the final exam.

The program must be developed using functions so that the main() function consists mostly of function calls. This is exactly the same requirement as your midterm!

Below is a suggested list of functions for you to consider in the development of this project:

splashScreen()//displays game and developer’s information

askForUserNames()//requests for username

validateUserName()//validate username

switchPlayer()//switch from one player to another

resetGame()//reset the game when one concludes; this includes filling the array with vales 0-8

displayGrid()//display the grid after each player makes a move

playerMakeMove()//prompts player to make a move, invokes validatePlayersMove, checkPositionAvailability

validatePlayersMove()//validates that user entry X is such that 0<=X<=8

checkPositionAvailability()//check that the position selected by the user is available

checkWin()//check for a winning player

checkTie()//check for a tie

In the case of option two, additional functions you may want to consider are:

makeBestMove()//select best option

computerMakeMove()//used to make the move, in other words populate the array

The main() function must use a loop to keep the user in the program until he/she wants to quit. Users should be allowed to play as many games as they want.

You must use meaningful variable names.

You must comment your code.

You must use variables of the correct type and initialize them with a proper value.

Your program must detect a winner if there is one

Your program must determine if a tie occurs

Expert Answer

 // Tic_Tac_Toe.cpp

#include <iostream>
#include<string>
#include<cstdlib>

using namespace std;
char square[10] = {‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′};
string name;
int splashScreen()//displays game and developer�s information
{
cout<<“Tic Tac Toe”<<endl;
cout<<“Developed by XXYYZZ”<< endl;
}
int askForUserNames()//requests for username
{

cout<<“Enter the player name:”<<endl;
getline (cin, name);
return 0;
}
int validateUserName(string name)//validate username
{
for (int i=0;i<name.length();i++)
{
if((name[i]>=’a’|| name[i]>=’A’)&&(name[i]<=’z’||name[i]<=’Z’))
{

}
else
{
return 0;

}
}
return 1;
}
int switchPlayer(int player)//switch from one player to another
{
player++;
return player%2;
}
int resetGame()//reset the game when one concludes; this includes filling the array with vales 0-8
{
for(int i=0;i<9;i++)
{
square[i]=(char)(i+48);
}
return 0;
}
int displayGrid()//display the grid after each player makes a move
{
cout << “Player 1 (“<<name<<“) – Player 2 (O)” << endl << endl;
cout << endl;

cout << ” | | ” << endl;
cout << ” ” << square[0] << ” | ” << square[1] << ” | ” << square[2] << endl;

cout << “_____|_____|_____” << endl;
cout << ” | | ” << endl;

cout << ” ” << square[3] << ” | ” << square[4] << ” | ” << square[5] << endl;

cout << “_____|_____|_____” << endl;
cout << ” | | ” << endl;

cout << ” ” << square[6] << ” | ” << square[7] << ” | ” << square[8] << endl;

cout << ” | | ” << endl << endl;

return 0;

}
int validatePlayersMove(int choice)//validates that user entry X is such that 0<=X<=8
{
if(choice>=0&&choice<=8)
{
return 1;
}
return 0;
}
int checkPositionAvailability(int choice)//check that the position selected by the user is available
{

if(square[choice]!=’O’&&square[choice]!=’X’)
{
return 1;
}
return 0;
}

int playerMakeMove()//prompts player to make a move, invokes validatePlayersMove, checkPositionAvailability
{
int choice;

while(1)
{
cout<<” Make a move: “<<endl;
cin>>choice;
if(validatePlayersMove(choice))
{
if(checkPositionAvailability(choice))
{

break;
}
else
{
cout<<“invalid move”;
}
}
else
cout<<“invalid move”;
}

char mark;

mark=’X’;

if (choice == 0 && square[0] == ‘0’)

square[0] = mark;
else if (choice == 1 && square[1] == ‘1’)

square[1] = mark;
else if (choice == 2 && square[2] == ‘2’)

square[2] = mark;
else if (choice == 3 && square[3] == ‘3’)

square[3] = mark;
else if (choice == 4 && square[4] == ‘4’)

square[4] = mark;
else if (choice == 5 && square[5] == ‘5’)

square[5] = mark;
else if (choice == 6 && square[6] == ‘6’)

square[6] = mark;
else if (choice == 7 && square[7] == ‘7’)

square[7] = mark;
else if (choice == 8 && square[8] == ‘8’)

square[8] = mark;

}

int checkWin()//check for a winning player
{
if (square[0] == square[1] && square[1] == square[2])

return 1;
else if (square[3] == square[4] && square[4] == square[5])

return 1;
else if (square[6] == square[7] && square[7] == square[8])

return 1;
else if (square[0] == square[3] && square[3] == square[6])

return 1;
else if (square[1] == square[4] && square[4] == square[7])

return 1;
else if (square[2] == square[5] && square[5] == square[8])

return 1;
else if (square[0] == square[4] && square[4] == square[8])

return 1;
else if (square[2] == square[4] && square[4] == square[6])

return 1;

else
return 0;
}
int checkTie()//check for a tie
{
if (square[1] != ‘1’ && square[2] != ‘2’ && square[3] != ‘3’
&& square[4] != ‘4’ && square[5] != ‘5’ && square[6] != ‘6’
&& square[7] != ‘7’ && square[8] != ‘8’ && square[0] != ‘0’)

return 1;
return 0;
}

int makeBestMove()//select best option
{

}
int computerMakeMove()//used to make the move, in other words populate the array
{
int choice;
do
{
choice=rand()%9;

if(square[choice]!=’X’&& square[choice]!=’O’)
{
break;
}

}
while(1);

char mark=’O’;

if (choice == 0 && square[0] == ‘0’)

square[0] = mark;
else if (choice == 1 && square[1] == ‘1’)

square[1] = mark;
else if (choice == 2 && square[2] == ‘2’)

square[2] = mark;
else if (choice == 3 && square[3] == ‘3’)

square[3] = mark;
else if (choice == 4 && square[4] == ‘4’)

square[4] = mark;
else if (choice == 5 && square[5] == ‘5’)

square[5] = mark;
else if (choice == 6 && square[6] == ‘6’)

square[6] = mark;
else if (choice == 7 && square[7] == ‘7’)

square[7] = mark;
else if (choice == 8 && square[8] == ‘8’)

square[8] = mark;

return 0;
}

int main()
{
int player=1;
splashScreen();
while(1)
{
askForUserNames();
if(validateUserName(name))
{
break;
}
else
cout<<“invalid name”<<endl;
}

displayGrid();
while(1)
{
if(player==1)
playerMakeMove();
else
computerMakeMove();
displayGrid();
if(checkWin())
{
if(player==1)
{
cout<<“Player “<<name<<” win”<<endl;

}
else
cout<<“Computer win”<<endl;
break;
}
else if(checkTie())
{
cout<<“tie”<<endl;
break;
}
player=switchPlayer(player);

}

return 0;
}

/////////////////////////////////////////////

outputs:

///////////////////////////////////////

Top Grade Homework
Order NOW For a 10% Discount!
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents