Chess960

Chess960, also known as Fischer random chess, is a variant of the game of chess in which the initial position of the pieces is selected randomly. Kokopu provides support for this variant.

The following example shows how to initialize a Position for Chess960 with one of the 960 possible initial positions. See https://chess960.net/start-positions/ for a exhaustive list of all possible initial positions and their corresponding ID's (also denoted as scharnaglCode).

var kokopu = require('kokopu');

var scharnaglCode = 42; // any integer value between 0 and 959 inclusive
var position = new kokopu.Position('chess960', scharnaglCode); // initialize the position for Chess960, with initial position 42

position.variant(); // returns 'chess960', meaning that the position is configured for Chess960

console.log(position.ascii());
// +---+---+---+---+---+---+---+---+
// | n | n | q | r | b | b | k | r |
// +---+---+---+---+---+---+---+---+
// | p | p | p | p | p | p | p | p |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// | P | P | P | P | P | P | P | P |
// +---+---+---+---+---+---+---+---+
// | N | N | Q | R | B | B | K | R |
// +---+---+---+---+---+---+---+---+
// w DHdh - (chess960)

It is also possible to load a PGN file containing some Chess960 games. The corresponding entries include the following headers, specifying the variant and the initial position:

[FEN "bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w KQkq - 0 1"]
[Setup "1"]
[Variant "Chess960"]

An example of such file is provided here: chess960.pgn.

var kokopu = require('kokopu');
var fs = require('fs');

// Read the content of the PGN file provided above.
var pgnText = fs.readFileSync('chess960.pgn', 'utf8');

// Parse the first game.
var game = kokopu.pgnRead(pgnText, 0);

game.variant(); // 'chess960'

console.log(game.initialPosition().ascii());
// +---+---+---+---+---+---+---+---+
// | b | b | q | n | n | r | k | r |
// +---+---+---+---+---+---+---+---+
// | p | p | p | p | p | p | p | p |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// |   |   |   |   |   |   |   |   |
// +---+---+---+---+---+---+---+---+
// | P | P | P | P | P | P | P | P |
// +---+---+---+---+---+---+---+---+
// | B | B | Q | N | N | R | K | R |
// +---+---+---+---+---+---+---+---+
// w FHfh - (chess960)