npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chess-engine-ts

v0.6.56

Published

A Chess Engine written in Typescript using bitboards

Downloads

25

Readme

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