Wondering what’s next for npm?Check out our public roadmap! »

    kokopu

    1.9.1 • Public • Published

    Kokopu

    Kokopu is a JavaScript library for chess applications. It implements the chess game rules, and provides tools to read/write the standard chess file formats (PGN, FEN, UCI, etc.).

    https://www.npmjs.com/package/kokopu

    Build Status Coverage Status

    Download

    https://kokopu.yo35.org/dist/kokopu.zip

    Documentation

    https://kokopu.yo35.org/

    Features

    • Chess move generation.
    • Check, checkmate and stalemate detection.
    • Move legality check.
    • Algrebraic notation parsing and generation.
    • FEN notation parsing and generation.
    • UCI move parsing and generation.
    • PGN file parsing (including advanced PGN features such as commentaries, sub-variations, NAGs, non-standard starting position...).
    • Support Chess960 (also known as Fischer Random Chess).

    Used by

    Example

    var kokopu = require('kokopu');
    
    // Create a new position, play some moves...
    var position = new kokopu.Position();
    position.play('e4');
    position.play('e5');
    position.play('Nf3');
    
    // Display an ASCII-art representation of the position.
    console.log(position.ascii());
    
    // +---+---+---+---+---+---+---+---+
    // | r | n | b | q | k | b | n | r |
    // +---+---+---+---+---+---+---+---+
    // | p | p | p | p |   | p | p | p |
    // +---+---+---+---+---+---+---+---+
    // |   |   |   |   |   |   |   |   |
    // +---+---+---+---+---+---+---+---+
    // |   |   |   |   | p |   |   |   |
    // +---+---+---+---+---+---+---+---+
    // |   |   |   |   | P |   |   |   |
    // +---+---+---+---+---+---+---+---+
    // |   |   |   |   |   | N |   |   |
    // +---+---+---+---+---+---+---+---+
    // | P | P | P | P |   | P | P | P |
    // +---+---+---+---+---+---+---+---+
    // | R | N | B | Q | K | B |   | R |
    // +---+---+---+---+---+---+---+---+
    // b KQkq -
    
    // List the available moves.
    var moves = position.moves();
    console.log(moves.map(function(move) {
      return position.notation(move);
    }));
    
    // [ 'a6', 'a5', 'b6', 'b5', 'c6', 'c5', 'd6','d5', 'f6', 'f5', 'g6',
    // 'g5', 'h6', 'h5', 'Na6', 'Nc6', 'Qe7', 'Qf6', 'Qg5', 'Qh4', 'Ke7',
    // 'Be7', 'Bd6', 'Bc5', 'Bb4', 'Ba3', 'Nf6', 'Nh6', 'Ne7' ]
    

    More examples available in documentation.

    Install

    npm i kokopu

    DownloadsWeekly Downloads

    106

    Version

    1.9.1

    License

    LGPL-3.0-or-later

    Unpacked Size

    444 kB

    Total Files

    111

    Last publish

    Collaborators

    • avatar