chess-console
Version:
ES6 Module for playing chess
31 lines (25 loc) • 954 B
JavaScript
/**
* Author and copyright: Stefan Haack (https://shaack.com)
* Repository: https://github.com/shaack/chess-console
* License: MIT, see file 'LICENSE'
*/
import {Observe} from "cm-web-modules/src/observe/Observe.js"
import {COLOR} from "cm-chessboard/src/Chessboard.js"
import {Chess} from "cm-chess/src/Chess.js"
export class ChessConsoleState {
constructor(props) {
this.chess = new Chess() // used to validate moves and keep the history
this.orientation = props.playerColor || COLOR.white
this.plyViewed = undefined // the play viewed on the board
}
observeChess(callback) {
const chessManipulationMethods = [
'move', 'clear', 'load', 'loadPgn', 'put', 'remove', 'reset', 'undo'
]
chessManipulationMethods.forEach((methodName) => {
Observe.postFunction(this.chess, methodName, (params) => {
callback(params)
})
})
}
}