Package com.zybooks.dsaj.fundamental
Class TicTacToe
java.lang.Object
com.zybooks.dsaj.fundamental.TicTacToe
Simulation of a Tic-Tac-Toe game (does not do strategy).
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the boardboolean
isWin
(int mark) Checks whether the board configuration is a win for the given player.static void
Test run of a simple gamevoid
putMark
(int i, int j) Puts an X or O mark at position i,j.toString()
Returns a simple character string showing the current board.int
winner()
Returns the winning player's code, or 0 to indicate a tie (or unfinished game).
-
Field Details
-
X
public static final int X- See Also:
-
O
public static final int O- See Also:
-
EMPTY
public static final int EMPTY- See Also:
-
-
Constructor Details
-
TicTacToe
public TicTacToe()Constructor
-
-
Method Details
-
clearBoard
public void clearBoard()Clears the board -
putMark
Puts an X or O mark at position i,j.- Throws:
IllegalArgumentException
-
isWin
public boolean isWin(int mark) Checks whether the board configuration is a win for the given player. -
winner
public int winner()Returns the winning player's code, or 0 to indicate a tie (or unfinished game). -
toString
Returns a simple character string showing the current board. -
main
Test run of a simple game
-