Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Data structures and algorithms java please can you give me easy code Q4: Tic-Tac-Toes is a game played in a three-by-three board by two players

Data structures and algorithms
java
please can you give me easy code 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 succeeds 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. X wins when sum of either a row, a column, or diagonal = 3 o Owins when sum of either a row, a column, or diagonal = -3 A tie is when the board is full and neither X wins nor wins Implement the program and run it for the following sample outputs to verify it: 2 0 0 0 playing board board array Figure 1: An illustration of Tic-Tac-Toe board using 2D Array Sample output 1: Player X please enter your move: 11 X Player O please enter your move: 11 Sorry you cannot place your mark here Player O please enter your move: 02 I 10 X Player X please enter your move: 22 110 1X1 IX Player O please enter your move: 01 1010 IXI X Player X please enter your move: 00 X|010 IXI X Player X is the winner Player X please enter your move: 00 X 11 Player O please enter your move: 11 XII 101 Player X please enter your move: 20 XI 101 XI Player O please enter your move: 10 XII 0101 X ! Player X please enter your move: 01 XXI 0101 XII Player O please enter your move: 1 2 XX1 000 XII Player O is the winner Player X please enter your move: 11 IXI 11 Player o please enter your move: 02 110 IX Player X please enter your move: 22 110 1X1 IX Player O please enter your move: 00 0110 IX IX Player X please enter your move: 01 O|X10 1X1 I IX Player O please enter your move: 21 OXO IX 10X Player X please enter your move: 1 2 0X10 1XX 10X Player O please enter your move: 10 OXO 10 of 11 01XX 10X Player X please enter your move: 20 OXO OXX XOX It's a tie

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Question

Discuss APV method of capital budgeting in detail

Answered: 1 week ago