Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(This code should use C++) Create a code where you will implement a computerized version of the game TicTacToe using a 2-dimensional array. This game

(This code should use C++) Create a code where you will implement a computerized version of the game TicTacToe using a 2-dimensional array. This game will be played by two humans sharing the same keyboard. The screen will also show the snapshot or the state of the board after every players move. You will store the board as a single 2-dimensional array of base type char that has 3 rows and 3 columns. Your program should: Keep track of whose turn it is (X or O) and inform the player about it. Allow a player to make a move. A player makes a move by informing your program at which location of the board he/she wants his/her respective symbol (X or O) to be placed. The options are as follows: 0 0, 0 1, 0 2, 1 0, 1 1, 1 2, 2 0, 2 1, 2 2. Notice that the player informs the row number, followed by a space, followed by a column number. Your program should verify if the move is valid (for example, 3 1 is not a valid move) and, in case of an invalid move, inform the user about it and ask for a valid move again. Verify if there is a winner after every players move and also if the board is already full but we have no winners. Your program should also allow the player to reinitialize the game to the beginning. On the next page is what your program should look like. Take note of spacing and punctuation. Your code must match this exact formatting (See next page): New Game: X goes first. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | | | | ----------------- | 1 | | | | ----------------- | 2 | | | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 0 0 You have entered row #0 and column #0 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | | | ----------------- | 1 | | | | ----------------- | 2 | | | | ----------------- O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 3 3 You have entered row #3 and column #3 Invalid entry: try again. Row & column numbers must be either 0, 1, or 2. O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 0 0 You have entered row #0 and column #0 That cell is already taken. Please make another selection. O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 1 1 You have entered row #1 and column #1 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | | | ----------------- | 1 | | O | | ----------------- | 2 | | | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 1 0 You have entered row #1 and column #0 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | | | ----------------- | 1 | X | O | | ----------------- | 2 | | | | ----------------- O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 0 1 You have entered row #0 and column #1 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | | ----------------- | 1 | X | O | | ----------------- | 2 | | | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 2 0 You have entered row #2 and column #0 Thank you for your selection. X IS THE WINNER!!! ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | | ----------------- | 1 | X | O | | ----------------- | 2 | X | | | ----------------- Another game? Enter Y or y for yes. Y New Game: X goes first. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | | | | ----------------- | 1 | | | | ----------------- | 2 | | | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 0 0 You have entered row #0 and column #0 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | | | ----------------- | 1 | | | | ----------------- | 2 | | | | ----------------- O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 1 1 You have entered row #1 and column #1 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | | | ----------------- | 1 | | O | | ----------------- | 2 | | | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 0 2 You have entered row #0 and column #2 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | | X | ----------------- | 1 | | O | | ----------------- | 2 | | | | ----------------- O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 0 1 You have entered row #0 and column #1 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | X | ----------------- | 1 | | O | | ----------------- | 2 | | | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 2 1 You have entered row #2 and column #1 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | X | ----------------- | 1 | | O | | ----------------- | 2 | | X | | ----------------- O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 1 0 You have entered row #1 and column #0 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | X | ----------------- | 1 | O | O | | ----------------- | 2 | | X | | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 1 2 You have entered row #1 and column #2 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | X | ----------------- | 1 | O | O | X | ----------------- | 2 | | X | | ----------------- O's turn. Where do you want your O placed? Please enter row number and column number separated by a space. 2 2 You have entered row #2 and column #2 Thank you for your selection. ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | X | ----------------- | 1 | O | O | X | ----------------- | 2 | | X | O | ----------------- X's turn. Where do you want your X placed? Please enter row number and column number separated by a space. 2 0 You have entered row #2 and column #0 Thank you for your selection. DRAW! NOBODY WINS! ----------------- |R\C| 0 | 1 | 2 | ----------------- | 0 | X | O | X | ----------------- | 1 | O | O | X | ----------------- | 2 | X | X | O | ----------------- Another game? Enter Y or y for yes. N Thank you for playing!

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

Students also viewed these Databases questions

Question

Create a workflow analysis.

Answered: 1 week ago