public class TicTacToe
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
static int |
CHAR_POSSIBILITIES |
An integer constant holding the number of possibilities for the chars
used which is three because the only eligible chars for TicTacToe
are x, o and space
|
static int |
COLS |
An integer constant holding the number of cols: 3
|
static int |
POSSIBILITIES |
An integer constant holding the number of possibilities for TicTacToe
boards which is three to the ninth
|
static int |
ROWS |
An integer constant holding the number of rows: 3
|
| Constructor | Description |
|---|---|
TicTacToe() |
| Modifier and Type | Method | Description |
|---|---|---|
private static java.lang.String |
addOne(java.lang.String s) |
Adds one to the last char of the String and adjust all of the other chars
appropriately
|
static java.lang.String |
boardToString(char[][] b) |
Converts a TicTacToe board into a String
|
private static boolean |
colWin(char[][] board) |
Returns whether or not the board has a column win on it
|
private static boolean |
diagonalWin(char[][] board) |
Returns whether or not the board has a diagonal win on it
|
static java.lang.String[] |
fillValues() |
Returns a String array with all the possible values for a TicTacToe board.
|
static boolean |
isWin(char[][] b) |
Returns whether the passed in board is a win by checking if
the board is valid and if there is a row win, a col win or
a diagonal win.
|
static boolean |
isWin(java.lang.String s) |
Returns whether a String is a win, by converting s to a board and
then checking the board produced using isWin.
|
static java.lang.String |
isWinString(char[][] b) |
Performs the same function as isWin but instead of returning a boolean,
it returns a String which allows the type of win to be returned.
|
static java.lang.String |
isWinString(java.lang.String s) |
Returns whether what type of win a String is, by converting s to a board
and then checking the board produced using isWinString.
|
static void |
main(java.lang.String[] args) |
|
static char[][] |
makeBoard(java.lang.String s) |
Makes and returns a board when sent a String
|
static int |
numChars(char[][] b,
char ch) |
Returns the number of the specified char on the board
|
private static boolean |
rowWin(char[][] board) |
Returns whether or not the board has a row win on it
|
static char[][] |
stringToBoard(java.lang.String board) |
Converts a TicTacToe String into a board, which is a 3 by 3 char array
|
static boolean |
valid(char[][] board) |
Checks if the board is valid.
|
static char |
whichLetter(char ch) |
Returns which letter the numerical equivalent (that this program uses)
of the chars are
|
public static final int ROWS
public static final int COLS
public static final int POSSIBILITIES
public static final int CHAR_POSSIBILITIES
public static int numChars(char[][] b,
char ch)
b - a 2d char array representing a TicTacToe boardch - the char to be countedpublic static boolean valid(char[][] board)
board - the TicTacToe board to be checkedpublic static java.lang.String boardToString(char[][] b)
b - the board to be convertedpublic static char[][] stringToBoard(java.lang.String board)
board - the String to be convertedpublic static char whichLetter(char ch)
ch - the char for whose numerical equivalent should be returnedpublic static char[][] makeBoard(java.lang.String s)
s - the String to be converted to a boardprivate static java.lang.String addOne(java.lang.String s)
s - a 9 character char composed of 0s, 1s and 2spublic static java.lang.String[] fillValues()
private static boolean diagonalWin(char[][] board)
board - the board to be checked, which is a 2D char arrayprivate static boolean rowWin(char[][] board)
board - the board to be checked, which is a 2D char arrayprivate static boolean colWin(char[][] board)
board - the board to be checked, which is a 2D char arraypublic static boolean isWin(char[][] b)
b - the board to be checkedpublic static java.lang.String isWinString(char[][] b)
b - the board as a 2D char arraypublic static boolean isWin(java.lang.String s)
s - the String to be checked for a winpublic static java.lang.String isWinString(java.lang.String s)
s - the String to be checked for a winpublic static void main(java.lang.String[] args)