1.0.8 • Published 5 years ago

bchess v1.0.8

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

bchess

Build Status License Codacy Badge Codecov Badge jsDelivr badge Heroku Badge

npm.io

A chess engine written in modern javascript with a minimal codebase.

Getting Started

Node

npm i bchess

CDN

<script src="https://cdn.jsdelivr.net/npm/bchess@1/dist/bchess.min.js"></script>

Usage

Simply include the library to start using it:

const { Chess, Action, Piece } = require("bchess");
const chess = new Chess({color: "white"});

You can also initialise a new game using FEN notation:

const chess = new Chess({fen:"kb5Q/p7/Pp6/1P6/4p3/4R3/4P1p1/6K1"});

API

move

Carry out the specified move

chess.move({from:"c2",to:"c4"});

A third option is available to specify the piece used for promotion (if available):

chess.move({from:"c2",to:"c4",promote:"Q"});

Returns

One or more Action flags.

The following is a list of possible flags:

  • MOVE
  • PLAYER_CAPTURE
  • OPPONENT_CAPTURE
  • CASTLE_KING
  • CASTLE_QUEEN
  • EN_PASSANT
  • PROMOTE
  • INVALID_ACTION

set

Set a piece down anywhere on the board:

chess.set({square: "h4", piece: new Piece("Q","white")});

available

Return an array of available moves a piece can make

chess.available({square:"e2"})

history

Get the current game history

chess.history

ascii

Returns an ascii string representing the current board

chess.ascii()

Example output:

  +--------------------------+
8 |  r  n  b  q  k  b  n  r  |
7 |  p  p  p  p  p  .  p  p  |
6 |  .  .  .  .  .  P  .  .  |
5 |  .  .  .  .  .  .  .  .  |
4 |  .  .  .  .  .  .  .  .  |
3 |  .  .  .  .  .  N  .  B  |
2 |  P  P  P  P  P  P  .  P  |
1 |  R  N  B  Q  .  R  K  .  |
  +--------------------------+
     a  b  c  d  e  f  g  h

The perspective of the board returned depends on the Chess myColor property.

Options

PropertyDescriptionValuesDefault
borderToggle border displaytrue / falsetrue
fileToggle file displaytrue / falsetrue
rankToggle rank displaytrue / falsetrue
unicodeDisplay unicode characters for pieces instead of FEN notationtrue/ falsefalse

score

Get the current game score

chess.score()

get

Fetch the information at a current square

chess.get({square:"g8"})

fen

Returns the current game state in FEN notation.

chess.fen()

Example output:

rnbqkbnr/ppppp1pp/5P2/1Q6/8/5N1B/PPPPPP1P/RNBQ1RK1

moves

Return the total move count (completed turns)

chess.moves

undo

Undo the most recent move

chess.undo();

turn

Whose turn is it?

chess.turn()

check

Returns pieces in check (and pieces checking them)

chess.check()

checkmate

Returns checkmate status for both sides

chess.checkmate()

stalemate

Returns stalemate status for both sides

chess.stalemate()

moveToSAN

Return the SAN notation of a move

chess.moveToSAN({from:"f2",to:"f4"})
1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago