Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is c++ code for tic tac toe :NO GLOBAL VARIABLES OR ARRAYS PLease take your time and add comments I need help Tic-Tac-Toe is

image text in transcribed

This is c++ code for tic tac toe :NO GLOBAL VARIABLES OR ARRAYS

PLease take your time and add comments I need help

Tic-Tac-Toe is a game that two parties play taking turns to mark a space (with X and O) in a 3x3 board. The player wins who succeeds to put three marks on a line (horizontal, vertical, or diagonal). As the first step to implementing the Tic-Tac-Toe game, you are required to create a function that draws the Tic-Tac-Toe board. This function will get called repeatedly until either all the nine spaces (or slots) on the board have been played ("Draw") or a player wins. Initially, the nine spaces will have numbers associated with individual slots, as shown in the screen shot below. Then, after each play, a user's or a computer's chosen a slots will show either X or O to designate the choice instead of the slot number. You will create a function to draw the board 1) initially with no choices made and 2) after each choice is made either by the player or by the computer Note: The first two lines in the screen shot print a welcome message, which should NOT be a part of the function to draw the Tic-Tac-Toe board rt 2: Create a function to check the input is within the valid range As a Tic-Tac-Toe board has only 9 slots, if the input position is less than 1 or greater than 9 then an error message should display (for example, "Invalid input: the position indicator has to be in the range of 1 to 9", as shown in the screen shot below). This error checking should be performed every time the user enters a number Part 3: Create a function to check the designated space is available After passing the input validation test in Part 2, the program has to check if the designated space is available. Create a function to examine whether the selected spot is available. Use the fact that the occupied spots (which were previously played) have either 'X' or 'O' character instead of the spot number (1 through 9). When the selected spot is available, mark it with 'X' or 'O'; if not, either ask the user to enter another number (as shown in the example below) or pick another random spot (when it is the computer's turn to play). In the example below, the space 6" that the user designates is already taken. The character "O" in the space means that the computer placed the marker there. Therefore, the program user enters "3", whose corresponding space is available asks the user to enter another position, and this time the Part 4: Create a function to check if we have a winner (and the program should end) Whenever a new position is marked, the program should check whether there is a winner If there is a winner, the winner is displayed and the program is terminated. If not, it will continue to play. In the example below, there are unplayed slots left (4, 5, 7, 8) but there are three X's on the top row. Therefore the user is a winner, which is displayed and the program is terminated Part 5: Create a main function that will call all these functions (and more if necessary) to play Tic-Tac-Toe Make sure to display the position that the computer chooses after each of the computer's turns, as shown in the example on the previous page

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

g. What types of roles did women have in the show?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago