Question
For this homework you are going to write the code for a console based game of Tic-Tac-Toe in C++. If you do not know how
For this homework you are going to write the code for a console based game of Tic-Tac-Toe in C++. If you do not know how to play Tic-Tac-Toe, the goal is to get three across a row, column, or diagonal.
The game board can be simulated with a two dimensional array. The player chooses a square by selecting its number. Play then alternates between the computer and player. When someone makes a move that wins the game, play stops. If all nine squares have been taken and no one has won - the game is a draw.
Make sure you show the game board after the final play. For simplicity, have the player go first and always be "X".
Sample Output:
A sample output of a program that plays the game is shown here (with user input in bold):
0 | 1 | 2 ----------- 3 | 4 | 5 ----------- 6 | 7 | 8 Enter the number of the square where you want to play: 4
0 | 1 | 2 ----------- 3 | X | 5 ----------- 6 | 7 | 8
Computer's turn
0 | 1 | 2 ----------- 3 | X | 5 ----------- 6 | O | 8 Enter the number of the square where you want to play: 3
0 | 1 | 2 ----------- X | X | 5 ----------- 6 | O | 8
Computer's turn
0 | O | 2 ----------- X | X | 5 ----------- 6 | O | 8 Enter the number of the square where you want to play: 5
0 | O | 2 ----------- X | X | X ----------- 6 | O | 8 X wins!
Requirements:
Since the purpose of this assignment is to help you review some of the fundamental topics from your first programming course that you will need to be successful in this course, you may NOT use classes to complete this assignment. No credit will be given for projects that define a class. The game should also be player between a human player and the computer player. Significant points will be deducted from submissions that implement a two human player game.
Your program should have some error checking. The user should not be allowed to enter illegal values. If an illegal value is entered, an appropriate message should be given, and the user re-prompted. The player obviously should not be able to play in a square that has already been taken either.
You should use appropriate commenting and indentation in your code, as discussed in your previous programming course. Make sure your name and a description of the program are in comments at the top of your code. If this is not done, expect significant points to be deducted from your score. You should have at least two functions (in addition to main) in this program: one to print the game board and one to check if someone has won the game. Feel free to have more functions if you would like, but you must have at least these two. Furthermore, you are not allowed to use GLOBAL VARIABLES . You need to pass parameters to these functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started