chess-console is a chess game client framework, which uses cm-chessboard and Bootstrap 4 to create a browser based, mobile friendly, responsive chess game gui.
Used by chessmail as a framework for an online chess computer.
Because if its component architecture chess-console is expandable for all kind of chess pages. You may check out the Stockfish Player for chess-console, with whom chess-console is a fully functional online chess computer.
- Option 1: Download from GitHub and run
npm install
without parameters, or - Option 2: Install the npm package with
npm install --save chess-console
ChessConsole(container, player, opponent, props)
- container: DOM parent element
- player: {name: playerName, type: Class of player, props: {}}
- opponent: {name: opponentName, type: Class of opponent, props: {}}
- props: Properties
{
// chess console
locale: navigator.language, // locale for i18n
playerColor: COLOR.white, // the players color (color at bottom)
pgn: undefined // initial pgn, can contain header and history
// Sound
soundSpriteFile: "/assets/sounds/chess_console_sounds.mp3",
// Board
chessboardSpriteFile: "/assets/images/chessboard-sprite.svg",
// Persistence
savePrefix: "ChessConsole" // the name in LocalStorage
}
chessConsole.state
{
this.chess = new Chess()
this.playerColor = props.playerColor || COLOR.white
this.orientation = props.playerColor || COLOR.white
this.plyViewed = 0
this.plyCount = 0
}
returns the white player
return the black player
return the player who can make a move, null if game_over
Loads the history part of a PGN, the metadata is ignored
Request the nextMove from playerToMove()
Take back the last move
Set a position and player color
Like initGame(props)
, but sends newGame
event via messageBroker.
chessConsole.messageBroker
Messages:
export const MESSAGE = {
newGame: function newGame(props) { // A new game was started
this.props = props
},
initGame: function initGame(props) { // The game was initialized
this.props = props
},
gameOver: function gameOver(wonColor) { // w, b, null for draw
this.wonColor = wonColor
},
moveRequest: function moveRequest(player) {
this.player = player
},
legalMove: function legalMove(player, move, moveResult) {
this.player = player
this.move = move
this.moveResult = moveResult
},
illegalMove: function illegalMove(player, move) {
this.player = player
this.move = move
},
moveUndone: function moveUndone() {
},
load: function load() {
}
}
Source code license: MIT,
License for the Sounds: CC BY 4.0,
License of the SVG pieces CC BY-SA 3.0.
Copyright © shaack.com engineering.