public class TicTacToe
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
boardFull(java.lang.String[][] board)
Is the board completely full of x and o moves?
|
static java.lang.String[][] |
genBoard()
Generate an initial board
|
static boolean |
makeMove(java.lang.String player,
java.lang.String[][] board,
int row,
int col)
Record a move of the player at the row and column.
|
static java.lang.String |
prettyString(java.lang.String[][] board)
Returns a standard view of the current board
|
static void |
verifyValidCol(int col)
Check that the col is between 0 and 2, inclusively, throwing IllegalArgumentException if not.
|
static void |
verifyValidPlayer(java.lang.String player)
Check that the specified player is "x" or "o" and throw an
IllegalArgumentException if it is not.
|
static void |
verifyValidRow(int row)
Check that the row is between 0 and 2, inclusively, throwing IllegalArgumentException if not.
|
static boolean |
winFor(java.lang.String player,
java.lang.String[][] board)
Does the board contain a win for the player? If it does, this method must return true
even if the board also contains a win for the other player.
|
public static java.lang.String[][] genBoard()
public static void verifyValidPlayer(java.lang.String player)
player
- should be "x" or "o"public static void verifyValidRow(int row)
row
- should be between 0 and 2, inclusivelypublic static void verifyValidCol(int col)
col
- should be between 0 and 2, inclusivelypublic static java.lang.String prettyString(java.lang.String[][] board)
board
- the current 3x3 tic tac toe boardpublic static boolean makeMove(java.lang.String player, java.lang.String[][] board, int row, int col)
verifyValidPlayer(java.lang.String)
)
verifyValidRow(int)
and verifyValidCol(int)
)
player
- an "x" or an "o"board
- a 3x3 String[][] arrayrow
- an integer between 0 and 2 inclusivelycol
- an integer between 0 and 2 inclusivelypublic static boolean boardFull(java.lang.String[][] board)
board
- a 3x3 String[][] arraypublic static boolean winFor(java.lang.String player, java.lang.String[][] board)
player
- An "x" or "o". Any other input should throw an IllegalArgumentExceptionboard
- A 3x3 String[][] array