Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TicTacToeBoard interface //Note: By convention, the player with symbol Mark.X always goes first public interface TicTacToeBoard { public final static int ROW_COUNT = 3; public

TicTacToeBoard interface //Note: By convention, the player with symbol Mark.X always goes first public interface TicTacToeBoard { public final static int ROW_COUNT = 3; public final static int COLUMN_COUNT = 3; //part of pre: 0 <= row < ROW_COUNT && 0 <= column < COLUMN_COUNT //part of post: rv == null <==> the (row, column) spot on the // board is empty public Mark getMark(int row, int column); //part of pre: 0 <= row < ROW_COUNT && 0 <= column < COLUMN_COUNT //part of pre: getMark(row, column) == null //part of pre: !isGameOver() //post: Left to student public void setMark(int row, int column); //part of post: rv == null <==> it is neither player's turn (i.e. // game is over) //part of post: number of Marks on board is even rv == Mark.X //part of post: number of Marks on board is odd rv == Mark.O public Mark getTurn(); //part of post: Left to student (see Tic-tac-toe rules in order // to fill this out) public boolean isGameOver();

//part of pre: isGameOver() //part of post: rv == null <==> neither player won (i.e. the game // ended in a tie) public Mark getWinner(); } Mark enumeration public enum Mark { X, O; } TicTacToeBoard implementation public class TicTacToeBoardImpl implements TicTacToeBoard { //Symbolics: protected static final int NO_MOVE = -1; protected static final int NO_MATCH = -1; protected int[] movesArray; public TicTacToeBoardImpl() { final int CELL_COUNT = ROW_COUNT*COLUMN_COUNT; movesArray = new int[CELL_COUNT]; for(int i = 0; i < CELL_COUNT; i++) { movesArray[i] = NO_MOVE; } } . . }

Complete the TicTacToeBoardImpl class shown above. You are not allowed to add any further data members, but are free to add methods to the TicTacToeBoardImpl that are not found in the TicTacToeBoard interface. Also, override the toString() method (inherited from Object) in the TicTacToeBoardImpl class to produce the following format (note: not all fonts are monospaced): X| | _____ |O| _____ O| |X

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