Methods
displayBoard(board) → {undefined}
Takes in a board and logs it to the console.
It should call your formatRow helper function.
Each row should be separated by a line of "-". The
length of which should be three times the board length.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
displayBoard is only in charge of logging the board to the console.
- Type
- undefined
formatRow(row) → {string}
Takes in a row of the board and returns the elements
separated by " | ". If the element is null is should be replaced with " "
Parameters:
Name | Type | Description |
---|---|---|
row |
Array |
- Source:
Returns:
- Type
- string
getCol() → {number}
Asks user for col input and returns col.
- Source:
Returns:
col (should be 1 lower than user because people count from 1)
- Type
- number
getRow() → {number}
Asks user for row input and returns row. Use questionInt
- Source:
Returns:
row (should be 1 lower than user because people count from 1)
- Type
- number
horizontalWinnerOrNull(board) → {string|null}
Takes in a board and determines if there is a
horizontal winner. If there is, it should return that winner.
Otherwise it should return null.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
Returns either the winner or null.
- Type
- string | null
isBoardFull(board) → {boolean}
Takes in a board and returns whether or not the board
is completely full.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
isBoardFull ?
- Type
- boolean
isGameOver(board) → {string|boolean}
Takes in a board and determines wether or not a game
is over. If there is a winner return that winner
*Hint* Use your winnerOrNull (previous functions) and isBoardFull helper functions
to either return the winner, true, or false.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
Returns either the winner (truthy),
true (which implies a tie), or false (game is NOT over)
- Type
- string | boolean
isValidPosition(row, col, board) → {boolean}
Takes in a row, column, and board and determines whether or not
that space is available to be chosen. If the spaces value is null,
it is available.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | |
col |
number | |
board |
Array.<Array> |
- Source:
Returns:
Is the position valid.
- Type
- boolean
leftDiagonalWinnerOrNull(board) → {string|null}
Takes in a board and determines if there is a
top left down diagonal winner. If there is, it should return that winner.
Otherwise it should return null.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
Returns either the winner or null.
- Type
- string | null
makeBoard(length) → {Array.<Array>}
Takes in an optional length argument and
returns a matrix grid of that length filled with null.
It should default to length of 3 if no argument is provided.
Parameters:
Name | Type | Description |
---|---|---|
length |
number |
- Source:
Returns:
- Type
- Array.<Array>
placeMark(row, col, sym, board) → {Array.<Array>}
Takes in a row, column, symbol, and board and updates the board to
have the symbol at the row / col.
Returns the updated board.
Parameters:
Name | Type | Description |
---|---|---|
row |
number | |
col |
number | |
sym |
string | |
board |
Array.<Array> |
- Source:
Returns:
Updated board.
- Type
- Array.<Array>
play()
Uses readline-sync's questionInt to find out how many rows / cols it will have.
Because it's a square only one call should be made.
Should create a symbol variable that starts at value "x"
Should create a board variable and call makeBoard.
Should create a gameOver variable and initialize it to false.
while the game is not over it should:
display the board
call takeTurn and switchSymbol
if the game is over is should say the symbol that won like: "x is the winner!"
If the game is a tie it should say "Tie Game!"
update game over to the result of isGameOver
When the game is over use readline-sync keyInYN method to ask the user
to play gain.
If they answer "y" play should call itself, otherwise it
should log "Goodnight!"
- Source:
rightDiagonalWinnerOrNull(board) → {string|null}
Takes in a board and determines if there is a
top right down diagonal winner. If there is, it should return that winner.
Otherwise it should return null.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
Returns either the winner or null.
- Type
- string | null
switchSymbol(sym) → {string}
Takes in a string symbol (either x or o) and returns
the opposite.
Parameters:
Name | Type | Description |
---|---|---|
sym |
string |
- Source:
Returns:
The opposite symbol
- Type
- string
takeTurn(sym, board) → {undefined}
Takes in a symbol and a board.
Uses the symbol to tell the user it's their turn.
calls getRow and getCol.
checks to see if that position is valid.
If the position is not valid, it should tell the user
"Invalid Position" and call itself to retake the turn.
If the position is valid, it should mark the board
appropriately.
Parameters:
Name | Type | Description |
---|---|---|
sym |
string | Current users symbol |
board |
Array.<Array> |
- Source:
Returns:
Should place mark or call itself again.
- Type
- undefined
verticalWinnerOrNull(board) → {string|null}
Takes in a board and determines if there is a
vertical winner. If there is, it should return that winner.
Otherwise it should return null.
Parameters:
Name | Type | Description |
---|---|---|
board |
Array.<Array> |
- Source:
Returns:
Returns either the winner or null.
- Type
- string | null