Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you shall implement Tic-Tac-Toe (a two-player game) using a 3x3 two-dimensional char array. Your array shall have 3 rows and 3 columns

In this assignment you shall implement Tic-Tac-Toe (a two-player game) using a 3x3 two-dimensional char array. Your array shall have 3 rows and 3 columns (row and column indices are from 0 to 2). You shall initialize all elements of your array with character 'v'. Therefore, at start of the game the tic-tac-toe board looks like: v v v v v v v v v Player-1 is assigned 'X' symbol and player-2 is assigned 'O' symbol. Player-1 shall start the game and enter row index and column index where (s)he wants to place an 'X'. The board is updated and displayed. Now player-2 is asked to enter row and column indices. One possible run of game is as follows: v v v v v v v v v Player1- enter row and column: 0 0 X v v v v v v v v Player2- enter row and column: 0 1 X O v v v v v v v Player1- enter row and column: 1 1 X O v v X v v v v Player2- enter row and column: 2 2 X O v v X v v v O Player1- enter row and column: 1 0 X O v X X v v v O Player2- enter row and column: 2 1 X O v X X v v O O Player1- enter row and column: 2 0 X O v X X v X O O Player 1 wins If any player tries to enter wrong indices e.g. row=3 column=2 then the program should display a message "Invalid choice - try again". Similarly, if the player tries to enter indices where an 'X' or 'O' is already present then again the program responds by a message "Invalid choice - try again". One possible program run is as follows: v v v v v v v v v Player1- enter row and column: 3 2 Invalid choice - try again Player1- enter row and column: 1 1 v v v v X v v v v Player2- enter row and column: 0 2 v v O v X v v v v Player1- enter row and column: 1 1 Invalid choice - try again Player1- enter row and column: 2 0 v v O v X v X v v Player2- enter row and column: 2 2 v v O v X v X v O Player1- enter row and column: 1 2 v v O v X X X v O Player2- enter row and column: 1 0 v v O O X X X v O Player1- enter row and column: 0 0 X v O O X X X v O Player2- enter row and column: 0 1 X O O O X X X v O Player1- enter row and column: 2 1 X O O O X X X X O TIE!! The game can have any of three outcomes "Player 1 wins", "Player 2 wins" or "TIE!!" NOTE In your implementation, you should break your problem into different functions. A rule of thumb is that one function should be responsible for carrying out a single task.

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

What is an advance pricing agreement?

Answered: 1 week ago

Question

You have

Answered: 1 week ago