Chess board with rule enforcement and state feedback, written in JavaScript.
-
Inside of index.js, you may list (in order) the moves to be made on the board, alternating between light and dark, with the
makeMove("start square", "end square")
function, with start"start square"
and"end square"
both being LetterNumber square coordinates. -
You can optionally set board state from a FEN String by using the
set_FEN("FEN string")
function.
-
getBoardJSON()
-
Allows you to get the current board state in form of an 8x8 2D array, the first dimension being the rows of the y axis and the second being each square along the x.
-
Each square has a
color
(either '#' (dark) or ' ' (light)) and acoordinate
in the form of LetterNumber, and apiece
. If there is not currently a piece on a given square, thepiece
value will be equal tonull
. Otherwise, it will have a piece object.
-
-
makeMove()
- Takes 2 parameters, a start and end position, both in "LetterNumber" format (ex.
makeMove("e2", "e4")
). If the move results in check, makeMove will return 1. If the move results in checkmate, it will return 2. If the move results in a stalemate, it wrill return 3. If the move is illegal or there is no piece on the starting square, it will return -1. If it is not the players turn, it will return -2. If the input is invalid, it will return -3.
- Takes 2 parameters, a start and end position, both in "LetterNumber" format (ex.
-
getPly()
- Returns the current ply, being either
"Light"
or"Dark"
.
- Returns the current ply, being either
-
resetBoard()
- Resets all pieces to their default starting positions.
-
clearBoard()
- Removes all pieces from the board. Implemented by default in
set_FEN()
.
- Removes all pieces from the board. Implemented by default in
-
get_FEN()
- Returns the FEN String representation of the current board state.
-
set_FEN()
- Sets the board state from any valid FEN String (ex.
set_FEN("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 0")
)
- Sets the board state from any valid FEN String (ex.
-
coordToAlpha()
- Converts an array of [y, x] (being a valid board coordinate) into a LetterNumber result.
- For use in
makeMove()
given it only takes LetterNumber for start and end.