All Projects → ajax333221 → isepic-chess

ajax333221 / isepic-chess

Licence: MIT license
♞ JavaScript chess utility library.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to isepic-chess

Online-Chess
A chess website where people can play against each other online.
Stars: ✭ 28 (+75%)
Mutual labels:  chess
react-pendulum
A React Context utility library.
Stars: ✭ 15 (-6.25%)
Mutual labels:  utility-library
lila-tablebase
Tablebase server
Stars: ✭ 51 (+218.75%)
Mutual labels:  chess
tea-chess
A chess-themed tutorial on writing an SPA in Bucklescript-TEA
Stars: ✭ 28 (+75%)
Mutual labels:  chess
chess
The game of Chess
Stars: ✭ 25 (+56.25%)
Mutual labels:  chess
DPTLib
My C libraries
Stars: ✭ 20 (+25%)
Mutual labels:  utility-library
ChessBoardScanner
Java based Chess Board Scanner, which converts 2D chess board image into a machine readable format a.k.a. Forsyth–Edwards Notation (FEN). It uses OpenCV and Deeplearning4j frameworks, complemented with some proprietary algorithms implemented for realizing the goal. It currently supports the chess board and pieces sets of the most common online c…
Stars: ✭ 32 (+100%)
Mutual labels:  chess
chess
An R package to read, write, create and explore chess games
Stars: ✭ 60 (+275%)
Mutual labels:  chess
js-markerclusterer
Create and manage clusters for large amounts of markers
Stars: ✭ 92 (+475%)
Mutual labels:  utility-library
snatchblock
A strictly typed utility library.
Stars: ✭ 1,059 (+6518.75%)
Mutual labels:  utility-library
chessboard-recognizer
Uses neural networks to extract chess positions from images
Stars: ✭ 59 (+268.75%)
Mutual labels:  chess
cm-pgn
Parse and create PGNs (Portable Game Notation for chess games)
Stars: ✭ 16 (+0%)
Mutual labels:  chess
chess graph
A program that will produce a graphical sunburst chart of chess openings from the PGN that is provided to it
Stars: ✭ 35 (+118.75%)
Mutual labels:  chess
Demolito
UCI Chess Engine
Stars: ✭ 41 (+156.25%)
Mutual labels:  chess
UnityChess
A 3D chess game made with Unity. Core game library submodule: https://github.com/ErkrodC/UnityChessLib
Stars: ✭ 90 (+462.5%)
Mutual labels:  chess
Mzinga
Open-source software to play the board game Hive.
Stars: ✭ 57 (+256.25%)
Mutual labels:  chess
stockfish.js
The strong open source chess engine Stockfish compiled to JavaScript and WebAssembly using Emscripten
Stars: ✭ 140 (+775%)
Mutual labels:  chess
underwater-chess
Chess, written in React, driven by a Stockfish-powered API
Stars: ✭ 20 (+25%)
Mutual labels:  chess
rgutil
rgutil是基于ES6创建的函数库工具
Stars: ✭ 22 (+37.5%)
Mutual labels:  utility-library
Chess.jl
Julia chess programming library.
Stars: ✭ 91 (+468.75%)
Mutual labels:  chess

Ic.js logo

isepic-chess.js

latest release npm version tested with Jest license official subreddit


isepic-chess.js is a chess utility library written in JavaScript, it provides features like legal moves calculation, FEN validation, SAN parsing, etc. (see: Features).

Flexibility: it strives to be flexible (inspired by JavaScript) and attempts to make things work without easily giving up and throwing errors.

Code coverage: the extra flexibility adds extra complexity and paths to be tested, but despite this, the code coverage is 98~% (as of v6.0.0).

Perft-tested: each release is tested against known Perft positions to ensure that the move generation tree of legal moves do not vary from the correct count.

UI-less: all the bloating code that a user interface brings is completely separated into this other project: Isepic Chess UI.

Dependency-less: does not depend on any other library.

📌 Table of contents

🖱️ Installation

# NPM
npm install isepic-chess

Then: const {Ic} = require("isepic-chess");


# Web browser
<script src="./isepic-chess.js"></script>

The variable Ic will be added to window.

💚 Node.js example

const { Ic } = require('isepic-chess');

var example_pgn = `[Event "m1 London"]
[Site "?"]
[Date "1861.07.??"]
[Round "9"]
[White "Kolisch, Ignatz"]
[Black "Anderssen, Adolf"]
[Result "0-1"]
[Annotator "JvR"]
[SetUp "1"]
[FEN "5r1k/pp4pp/3r3q/8/3PpP1P/1P2NbP1/PB1Q3K/R7 b - - 0 30"]
[PlyCount "13"]
[EventDate "1861.??.??"]

30... Rxf4 $1 {Anderssen starts fireworks.} 31. Qe1 (31.gxf4 $2 Qxh4+ 32.Kg1
Rg6+) 31... Rg6 (31...Rxh4+ $1 32.gxh4 Rg6 $1) 32. Bc1 (32.Ng2 $1) 32... Rxh4+
$1 33. gxh4 Qf4+ 34. Kh3 Bg2+ $1 35. Nxg2 Qf3+ 36. Kh2 Qxg2# { Anderssen won
the match by this mate (+4, =2, -3).} 0-1`;

var board = Ic.initBoard({
  pgn: example_pgn,
});

console.log(board.ascii());
//   +------------------------+
// 8 | .  .  .  .  .  .  .  k |
// 7 | p  p  .  .  .  .  p  p |
// 6 | .  .  .  .  .  .  r  . |
// 5 | .  .  .  .  .  .  .  . |
// 4 | .  .  .  P  p  .  .  P |
// 3 | .  P  .  .  .  .  .  . |
// 2 | P  .  .  .  .  .  q  K |
// 1 | R  .  B  .  Q  .  .  . |
//   +------------------------+
//     a  b  c  d  e  f  g  h

console.log(board.fen);
// "7k/pp4pp/6r1/8/3Pp2P/1P6/P5qK/R1B1Q3 w - - 0 37"

var fen_arr = [
  'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
  'r1bqk2r/pppp1pbp/2n2n2/4p3/5p2/2N3PN/PPPPP1BP/R1BQK2R w KQkq - 2 8',
  'r2qkb1r/pbp1p1p1/1pnp1n1p/5p2/4P2P/5NP1/PPPPKPB1/RNBQR3 w kq - 0 8',
  'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1',
  'r2qkbnr/ppp4p/2np1p2/4p3/3PP3/P2B1N2/1PP2PpP/RNBQ1RK1 b kq - 1 11',
];

/* transform each FEN into arrays with their legal UCI moves for the g2 square */
var mapped = fen_arr.map((fen) => Ic.fenApply(fen, 'legalSanMoves', ['g2']));

console.log(mapped);
// [
//  ["g2g3", "g2g4"],
//  ["g2f1", "g2f3", "g2e4", "g2d5", "g2c6"],
//  ["g2h3", "g2h1", "g2f1"],
//  [],
//  ["g2f1n", "g2f1b", "g2f1r", "g2f1q"]
// ]

/* get only the positions where the white king is not in its original square */
var filtered = fen_arr.filter((fen) => {
  var obj, rtn;

  rtn = false;
  obj = Ic.fenGet(fen, 'w');

  if (obj) {
    rtn = obj.w.kingBos !== 'e1';
  }

  return rtn;
});

console.log(filtered);
// [
//  "r2qkb1r/pbp1p1p1/1pnp1n1p/5p2/4P2P/5NP1/PPPPKPB1/RNBQR3 w kq - 0 8",
//  "r2qkbnr/ppp4p/2np1p2/4p3/3PP3/P2B1N2/1PP2PpP/RNBQ1RK1 b kq - 1 11"
// ]

👁️ Demo (from isepic-chess-ui)

https://ajax333221.github.io/isepic-chess-ui/

🚀 Features

  • Get legal moves
  • Lookahead moves that result in checkmate / draw
  • Check / checkmate / draw detection
  • Pawn promotion options
  • PGN import / export
  • UCI import / export
  • ASCII diagram
  • Material difference
  • Multiple boards at once
  • Number of attackers / defenders on a square
  • Navigable move history and helper methods (first, last, previous, undo move, reset, etc.)
  • Powerful FEN one-liner operations (Ic.fenApply() and Ic.fenGet())
  • Advanced FEN validation
  • SAN parsing

📖 Documentation

📄 Copyright and license

Copyright © 2022 Ajax Isepic (ajax333221)

Licensed under MIT License: http://opensource.org/licenses/mit-license.php

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].