A Multiplayer chess engine
npm install simple-chess-enginesimple-chess-engine is a multiplayer chess engine which keeps track of the board and produces valid possbile moves.``js`
const SimpleChessEngine = require('simple-chess-engine');
const game = new SimpleChessEngine();
`js`
/**
* Returns the current status of the game
*
* @returns {object}
{
"nextPlayer": "white",
"isCheck": false,
"isCheckmate": false,
"isStalemate": false
}
*/
game.getStatus();
`js`
/**
* Returns all the valid possible moves of a piece at the given position
* @param {string} position
*
* @returns {array}
["A3", "C3"]
*/
game.getPossibleMoves('B1');
`js`
/**
* Used to move a piece from source position to destination position
* @param {string} source
* @param {string} destination
*
* @returns {object}
{
"success": true | false,
"status" : {
"nextPlayer" : 'white' | 'black',
"isCheck" : true | false,
"isCheckmate": true | false,
"isStalemate": true | false
}
}
*
* NOTE :: In order to get the updated board, use the getBoard() method.
*/
game.makeMove('B1', 'C3');
`js`
/**
* Used to undo any previosly made move
*
* @returns {object}
{
"nextPlayer" : 'black' | 'white',
"isCheck" : true | false,
"isCheckmate": true | false,
"isStalemate": true | false
}
*
* NOTE :: In order to get the updated board, use the getBoard() method.
*/
game.undo();
`js`
/**
* Used to return the complete board
*
* @param {object} opts
* Supported opts:
* format: 'JSON' =>(Currently only JSON format is supported, any requested formats might be considered)
*
* @returns {object}
*
{
"A8": {
"color": "black",
javascriptiece": "rook"
},
"B8": {
"color": "black",
"piece": "bishop"
},
...
}
*/
game.getBoard();
`js`
let content = JSON.stringify({
A1: { color: "white", piece: "king" },
C1: { color: "black", piece: "king" },
A2: { color: "white", piece: "rook" }
});
let opts = { firstPlayer: 'white' };
/**
* Used to load custom board
* @param {string} content => Stringified JSON Object
* @param {object} opts
*
* Supported opts:
* firstPlayer = 'white' | 'black'
*
* @returns {object}
* Success Case
{
"success": "true",
"status": {
"nextPlayer": "white",
"isCheck": false,
"isCheckmate": false,
"isStalemate": false
}
}
* Failure Case
{
"success": "false",
"reasons": [...]
}
*/
game.loadBoard(content, opts);
`js`
let opts = { custom: true };
/**
* Used to reset the board
* @param {object} opts
*
* Supported opts:
* custom = true | false (resetGame with custom=true will reload the custom board which was previousy loaded (if any))
*
* NOTE :: resetGame with custom=false will remove custom board from memory
* NOTE :: In order to get the updated board, use the getBoard() method.
*/
game.resetGame();
`js``
/**
* Logs the complete chess board to the console
*/
game.displayBoard();
---
If you find this useful, you can support me by donating here...


(Supports GPay, Paytm, PhonePe, BHIM UPI, Credit Cards, Debit Cards, Netbanking...)