New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kokopu

Package Overview
Dependencies
Maintainers
0
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kokopu

A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.

  • 4.11.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
decreased by-70.99%
Maintainers
0
Weekly downloads
 
Created
Source

Kokopu

Kokopu is a JavaScript/TypeScript chess library. 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/

Migrate to 3.x and 4.x

Versions 3.0.0 and 4.0.0 introduce some breaking changes with regard to the previous versions. To determine whether your codebase needs to be adapted or not when upgrading Kokopu, please look at:

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 and generation (including advanced PGN features such as commentaries, sub-variations, NAGs, non-standard starting position...).
  • Support several chess variants:
    • Chess960, also known as Fischer Random Chess.
    • Antichess, also known as losing chess, giveaway chess, suicide chess...
    • Horde chess (following Lichess/Chess.com rules).

Kokopu is a headless library, meaning it does not provide any user interface. If you are interested in UI features (e.g. to be able to render a chessboard component within a web page), you may take a look at Kokopu-React, which is a React-based library built on top of Kokopu to provide these kind of features.

Example

const { Position } = require('kokopu');

// Create a new position, play some moves...
const position = new 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.
const moves = position.moves();
console.log(moves.map(move => 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.

Keywords

FAQs

Package last updated on 01 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc