0.6.56 • Published 18 days ago

chess-engine-ts v0.6.56

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

ChessEngineTS

ChessEngineTS is my implementation of a bitboard chess engine written in typescript

Features

  • Move generation
  • Load/Export FEN

In development

  • Search
  • Evaluation
  • Load/Export PGN
  • FEN validation
  • Move history feature

Installation

Run the following command to install the most recent version of chess-engine-ts from NPM:

npm install chess-engine-ts

or using yarn

yarn add chess-engine-ts

Example Code

The code below creates a board with pieces at starting position

import { Board } from 'chess-engine-ts'

const board = new Board();

User Interface

ChessEngineTS will only operate in the background of your program, using this API will make creating the user interface easier.

API

Constructor: Board( fen : string )

The Board() constructor takes an optional parameter which specifies the board configuration in Forsyth-Edwards Notation (FEN).

import { Board } from 'chess-engine-ts'

// board defaults to the starting position when called with no parameters
const board = new Board()

// pass in a FEN string to load a particular position
const board = new Board(
  '2q5/K7/1P2r2n/Q2n2P1/2p3P1/p1Pp1k2/2R2B2/8 w - - 0 1'
)

.overview()

Returns an array of elements consisting of piece data or empty squares(undefined)

import { Board } from 'chess-engine-ts';

const board = new Board()

console.log(board.overview())

//->    [
//      { type: 'r', color: 'b', square: 'a8' },
//      { type: 'n', color: 'b', square: 'b8' },
//      { type: 'b', color: 'b', square: 'c8' },
//      { type: 'q', color: 'b', square: 'd8' },
//      { type: 'k', color: 'b', square: 'e8' },
//      { type: 'b', color: 'b', square: 'f8' },
//      { type: 'n', color: 'b', square: 'g8' },
//      { type: 'r', color: 'b', square: 'h8' },
//      ...
//      {type: 'r', color: 'w', square: 'a1'},
//      {type: 'n', color: 'w', square: 'b1'},
//      {type: 'b', color: 'w', square: 'c1'},
//      {type: 'q', color: 'w', square: 'd1'},
//      {type: 'k', color: 'w', square: 'e1'},
//      {type: 'b', color: 'w', square: 'f1'},
//      {type: 'n', color: 'w', square: 'g1'},
//      {type: 'r', color: 'w', square: 'h1'}]

.loadFen(fen : string)

loads Fen

import { Board } from 'chess-engine-ts';

const board = new Board();

board.loadFen('rnbqkbnr/pppppppp/8/8/P7/8/1PPPPPPP/RNBQKBNR b KQkq - 0 1')

.exportFen() : string

Returns the FEN of the current position

import { Board } from 'chess-engine-ts'

const board = new Board();

board.move('a2', 'a4');

console.log(board.exportFen());

//-> rnbqkbnr/pppppppp/8/8/P7/8/1PPPPPPP/RNBQKBNR b KQkq - 0 1

.move(from : Square, to : Square) : boolean

Takes two arguments, both are of type Square (a1 | b1, c1 ... f8 | g8 | h8); whichs moves the piece from->to

if move is valid it will return true, else false.

import { Board } from 'chess-engine-ts';

const board = new Board();

board.move('a2', 'a4');

.validMoves(square : Square) : Square[]

Takes in one argument of type square, returns an array of valid moves of type Square(a1 | b1, c1 ... f8 | g8 | h8);

import { Board } from 'chess-engine-ts';

const board = new Board();

console.log(board.validMoves('a2'))

//->[ 'a3', 'a4' ]

.isCheck() : boolean

returns if current color is in check

import { Board } from 'chess-engine-ts';

const board = new Board('3b1q1q/1N2PRQ1/rR3KBr/B4PP1/2Pk1r1b/1P2P1N1/2P2P2/8 b - -');

console.log(board.isCheck())

//-> true

.isMate() : boolean

returns if current color has no legal moves and is in check

import { Board } from 'chess-engine-ts';

const board = new Board('3b1q1q/1N2PRQ1/rR3KBr/B4PP1/2Pk1r1b/1P2P1N1/2P2P2/8 b - -');

console.log(board.isMate())

//-> true

.isStalemate() : boolean

returns if current color has no legal moves and is not in check

import { Board } from 'chess-engine-ts';

const board = new Board('8/6p1/5p2/5k1K/7P/8/8/8 w - - -');

console.log(board.isStalemate())

//-> true
0.6.56

18 days ago

0.6.55

18 days ago

0.6.54

19 days ago

0.6.53

20 days ago

0.6.52

20 days ago

0.6.51

20 days ago

0.6.21

22 days ago

0.6.20

22 days ago

0.6.23

22 days ago

0.6.22

22 days ago

0.6.29

22 days ago

0.6.28

22 days ago

0.6.25

22 days ago

0.6.24

22 days ago

0.6.27

22 days ago

0.6.26

22 days ago

0.6.50

22 days ago

0.6.19

22 days ago

0.6.43

22 days ago

0.6.42

22 days ago

0.6.45

22 days ago

0.6.44

22 days ago

0.6.41

22 days ago

0.6.47

22 days ago

0.6.46

22 days ago

0.6.49

22 days ago

0.6.48

22 days ago

0.6.32

22 days ago

0.6.31

22 days ago

0.6.34

22 days ago

0.6.33

22 days ago

0.6.30

22 days ago

0.6.36

22 days ago

0.6.35

22 days ago

0.6.4

22 days ago

0.6.12

23 days ago

0.6.11

23 days ago

0.6.18

23 days ago

0.6.17

23 days ago

0.6.14

23 days ago

0.6.13

23 days ago

0.6.16

23 days ago

0.6.15

23 days ago

0.5.3

23 days ago

0.5.0

23 days ago

0.6.1

23 days ago

0.5.2

23 days ago

0.6.0

23 days ago

0.5.1

23 days ago

0.4.3

1 year ago

0.3.0

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.4

1 year ago

0.2.5

1 year ago

0.4.2

1 year ago

0.3.3

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago