Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this design project, you will implement a Tic-Tac-Toe game between a user and the computer. Tic- Tac-Toe is a game that two parties play

In this design project, you will implement a Tic-Tac-Toe game between a user and the computer. 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 that wins succeeds to placing three marks on a line (horizontal, vertical, or diagonal). There is NO requirement for strategy or logic in how the computer selects its move the computers move (play) can be random.
Design Specifications:
NOTE: This design cannot use arrays.
This design cannot use global variables.
Basic Implementation:
For the basic implementation, the user is the first player and the computer is the second player. Additionally, the user gets the marker X and the computer gets the marker O.
To receive full credit for the basic implementation, you must meet the following design specifications:
Function to draw the tic-tac-toe board (1)
The Tic-Tac-Toe game requires a function that draws the Tic-Tac-Toe board. This function will get called repeatedly until either all the nine spaces on the board have been played or a player wins.
Initially, the nine spaces will have numbers associated with their position, as shown in the screen shot below. After each play, the chosen space will show either an X or an O to designate the space was taken.
Function to check the input is within the valid range (2)
As a Tic-Tac-Toe board has only 9 spaces, if the input value is less than 1 or greater than 9 then an error message should be displayed (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.
Function to check the designated space is available (3)
After passing the input validation test, the program has to check if the designated space is available. Create a function to examine whether the selected space is available. Use the fact that the occupied space (which were previously played) have either X or O character instead of the space number (1 through 9). When the selected space is available, mark it with X or O of the player; if not, either ask the user to enter another number (as shown in the example below) or pick another random space (when it is the computers 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 asks the user to enter another value, and this time the user enters 3, whose corresponding space is available. Play will continue until an available space is selected.
Function to check if we have a winner (and the program should end) (4)
Whenever a new space 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 Xs on the top row. Therefore the user is a winner, which is displayed and the program is terminated.
Create a main() program (5)
The main() will play the complete Tic-Tac-Toe game including all the fore mentioned functions. The main() will play a new game if requested by the user. Other functions may be added as needed but are not required.
Better Implementation:
To receive full credit for the better implementation, you must meet the following design specifications:
Ask the user to flip a coin to determine who (either the user or the computer) should play first.
Ask the user to choose their own marker, between X and O.
Create a tally of user wins, losses and cats games
c++ only

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

Students also viewed these Databases questions