1.3.1 • Published 9 years ago

node-chess v1.3.1

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

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

1.3.1

9 years ago

1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0-alpha

9 years ago

0.10.0

9 years ago

0.9.3

9 years ago

0.9.2

9 years ago

0.9.1

9 years ago

0.9.0

9 years ago

0.8.0

9 years ago

0.7.2

9 years ago

0.7.1

9 years ago

0.7.0

9 years ago

0.6.0

9 years ago

0.5.0

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.0

9 years ago