Question: You are going to write a method (to be called validateBoard) that is going to validate whether or not a Tic-Tac-Toe board is possible. Tic-Tac-Toe

You are going to write a method (to be called validateBoard) that is going to validate whether or not a Tic-Tac-Toe board is possible. Tic-Tac-Toe is played on a 33 board and players take turns placing either an x or an o on the board. We will assume that in Tic-Tac-Toe, the player placing x will go first and that o will go second.

As the player placing x pieces goes first, and play alternates, a valid board is one in which there is either the same number or one more x game pieces on the board as there are o game pieces.

The board is represented by a 33 array that holds strings that represent the game piece at each location. A space can hold any of the following:

"x", representing an x game piece in that position

"o", representing an o game piece in that position

".", representing an empty position on the board

Input

The validateBoard method should take as input:

a 2-dimensional array that holds strings (representing the 3333game board where strings "x", o and . denoting the game piece in each location, as described above)

Processing

The new method will decide whether the incoming 2D array is represents a valid board. A valid board is defined to be a board in which there are either the same number of x as o game pieces, or one more x than o.

Output

If the board is determined to be valid, the method will return a boolean value of true. Otherwise, it will return false.You are going to write a method (to be called validateBoard) that Write this in JAVA

Sample input Sample output true true f"x" "X 1. false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!