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

node-chess

v1.3.1

Published

An isomorphic and fully customisable JavaScript chess engine

Downloads

59

Readme

Node-chess

A fully isomorphic and extensible chess engine with position analysis, board analysis, and computer opposition.

NPM version Travis build status

What does it do? How is it extensible?

Node-chess allows you extend the board and add your own rules. The analysis engine and computer player will automatically factor these changes/additions into their calculations and adjust accordingly.

With node-chess you can:

  • define your own pieces and modify existing pieces
    • (re-)define their notation, movement, value, and capture logic
  • add, change, and remove rules such as win and loss conditions
  • extend the existing engine to improve the calculations for your own variants

Installation

Add it as a dependency to your project

npm install node-chess

In the browser

<script src="node-chess.js">
	var game = chess.classic.engine();
</script>

The engine comes with a 'classic' implementation of Chess.

var chess = require("node-chess");
var game = chess.classic.engine();

Using the board

// Move the E2 pawn to E4
game.movePiece( { from: { file: 5, rank: 2 } , to: { file: 5, rank: 4 } });

// Move the B8 knight to C6 
game.movePiece( { from: { file: 2, rank: 8 }, to: { file: 3, rank: 6 } });

// Try and make an invalid move
// No piece is on B8
game.movePiece({ from: { file: 2, rank: 8 }, to: { file: 3, rank: 6 } }); === null; // true

// Promotion
// To a queen (by default)
game.movePiece({ from: { file: 1, rank: 7 }, to: { file: 1, rank: 8 } });

// To a rook
game.movePiece({ from: { file: 1, rank: 7 }, to: { file: 1, rank: 8 } }, "r");

// Print the available moves of the C6 knight to the console
console.log(classicEngine.getMoves({ file: 3, rank: 6 }));

Defining your own pieces

The 'super knight' moves 3 squares laterally before moving 1 square on the opposite axis!

var Direction = require("./engine/direction");
var customEngine = new chess.Engine();

var upLeft = makeMove(-1, 3);
var upRight = makeMove(1, 3);

var downLeft = makeMove(-1, -3);
var downRight = makeMove(1, -3);

var leftUp = makeMove(-3, 1);
var leftDown = makeMove(-3, -1);

var rightUp = makeMove(3, 1);
var rightDown = makeMove(3, -1);

function makeMove(file, rank) {
	return {
		canCapture: true,
		canMove: true,
		transforms: { file: file, rank: rank, canJump: true }
	}
}

var superKnight = {
	name: "SuperKnight",
	movement: [upLeft, upRight, downLeft, downRight, leftUp, leftDown, rightUp, rightDown],
	canQueen: false,
	canSpawn: true,
	value: 3.5,
	notation: "s"
}

customEngine.pieces.push(superKnight);

Analytics

Build Status