Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q4: Tic-Tac-Toes is a game played in a three-by-three board by two players (X and 0). The players alternate in placing their marks, starting with

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Q4: Tic-Tac-Toes is a game played in a three-by-three board by two players (X and 0). The players alternate in placing their marks, starting with player X. If either player s in getting three of his marks in a row, column, or diagonal, then the player wins. Design and implement a program that maintain a Tic-Tac-Toe and register the moves of the players and determine the winner. This program should work for any input. Notes: Use 2D array for the board of the game. The value of the cell can be O EMPTY represented by 0 O X represented by 1 O O represented by - 1 A player cannot place his mark on nonempty cell. The board starts with all empty cells and player X is the first player. Implement a method that prints a representation of the board to the screen as shown in the output. The game ends when either player wins or there is a tie. O X wins when sum of either a row, a column, or diagonal = 3 O O wins when sum of either a row, a column, or diagonal = -3 O Atie is when the board is full and neither X wins nor O wins Implement the program and run it for the following sample outputs to verify it: 0 1 2 XOO 1 -1 000 playing board board array Figure 1: An illustration of Tic-Tac-Toe board using 2D Array Sample output1: Player X please enter your move: 11 XI Player O please enter your move: 11 Sorry you cannot place your mark here Player o please enter your move: 0 2 110 X Player X please enter your move: 22 10 |X1 TIX Player O please enter your move: 01 1010 X T |X Player X please enter your move: 0 0 X|0|0 |X TX Player X is the winner Sample output2: Player X please enter your move: 00 XII TI Player O please enter your move: 11 XII 101 TT Player X please enter your move: 20 XII 101 X1 Player O please enter your move: 10 XII 0101 X1 Player X please enter your move: 01 XX1 0101 X1 Player O please enter your move: 1 2 XX1 01010 X1 Player O is the winner Sample output3! Player X please enter your move: 11 XI 11 Player O please enter your move: 02 110 X Player X please enter your move: 22 110 X TIX Player O please enter your move: 0 0 01 10 X IX Player X please enter your move: 01 0|X|0 1X TIX Player O please enter your move: 21 OXO 1X1 10X Player X please enter your move: 12 OXO |X|X 10X Player O please enter your move: 10 OXO O|X|X 10X Player X please enter your move: 20 O|XO O|X|X XOX It's a tie. data structure Java

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

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

=+ Where, how, why, and when are the products to be bought abroad?

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago