0.1.2 • Published 6 years ago

messy-chess v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

MessyChess

MessyChess is fast and well tested chessboard state manager.

It's used in production by MessyPlayground.

You are welcome to use it and contribute.

Quick tutorial

There are few ways to create initial game:

import Chess from 'messy-chess'

const game = new Chess() // creates default position
const game = new Chess(null) // creates empty board
const game = new Chess(fen) // create game from the given FEN

Read more about FEN here.

Now you can get different information about state of the game:

game.fen // returns FEN for the given position
game.board // returns 8x8 array with information about pieces
game.turn // whose turn is now? Returns 'w' or 'b'
game.inCheck
game.inCheckMate
game.inStalemate
// TODO: we don't yet have inDraw method!
game.getHistory({ verbose: true })
game.get('e2') // {type: 'p', color: 'w'}

Use getAvailableMoves for determining which moves are allowed in given position:

game.getAvailableMoves() // all moves
game.getAvailableMoves({ square: 'e2' }) // moves from given square

Also you can make/undo moves:

game.makeMove('e4') // pawn e2-e4
game.undoMove()

Other languages