Write a class (and a client class to test it) that encapsulates a tic-tac-toe bo
ID: 3547720 • Letter: W
Question
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A tic-tac-tow board looks like a table of three row and three columns partially or completely filled with the characters X and O. At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the tic-tac-toe board.
your default constructor should instantiate the array so that it represents an empty board.
you should include the following methods:
1. a method, returning a boolean, simulating a play with three parameters as follows: If the first parameter is true, then X is playing; otherwise, O is playing. The other two parameters represent what cell on the board is being played. If the play is legal, that is, the cell is a legal cell on the board and is empty, then the method should update the array and return true; otherwise, the array should not be updated and the method should return false.
2. a method returning how many valid plays have been made so far
3. a method checking if a player has won based on the contents of the board; this method takes no parameter. It returns X if the "X player" has won, O if the "O player" has won, T is the game was a tie. A player wins if he or she has placed an X (or an O) in all cells in a row, all cells in a column, or all cells in one of the two diagonals.
here is basic structure that teacher gave to us:
public class TTT
{private char [ ] [ ] board = new char [3] [3];
private static int counter = 0;
public TTT() {
public boolean move(boolean X, int r, int c)
{ if .........
public static int numplays()
{
return counter
public char winner
{
}
public void play()
{
}
public class TTTClient
{
TTT game = new TTT();
game.play()
}
Explanation / Answer
.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.