8.6.0 • Published 6 months ago

isepic-chess v8.6.0

Weekly downloads
465
License
MIT
Repository
github
Last release
6 months ago

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.

:pushpin: Table of contents

:computer_mouse: 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.

:green_heart: 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"
// ]

:eye: Demo (from isepic-chess-ui)

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

:rocket: 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
  • Puzzle mode (:construction: work in progress :construction:)

:book: Documentation

:page_facing_up: Copyright and license

Copyright © 2023 Ajax Isepic (ajax333221)

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

8.6.0

6 months ago

8.5.2

1 year ago

8.5.1

1 year ago

8.4.7

2 years ago

8.4.9

2 years ago

8.4.8

2 years ago

8.5.0

2 years ago

8.4.5

2 years ago

8.4.4

2 years ago

8.4.6

2 years ago

8.4.3

2 years ago

8.2.0

2 years ago

8.4.1

2 years ago

8.4.0

2 years ago

8.4.2

2 years ago

8.3.0

2 years ago

8.1.0

2 years ago

8.0.1

3 years ago

8.0.0

3 years ago

7.6.0

3 years ago

7.4.1

3 years ago

7.5.0

3 years ago

7.4.0

3 years ago

7.3.1

3 years ago

7.3.0

3 years ago

7.2.0

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.0

3 years ago

6.11.0

3 years ago

6.10.4

3 years ago

6.10.3

3 years ago

6.10.2

3 years ago

6.10.1

3 years ago

6.8.1

3 years ago

6.10.0

3 years ago

6.9.0

3 years ago

6.9.2

3 years ago

6.9.1

3 years ago

6.8.0

3 years ago

6.7.0

3 years ago

6.6.6

3 years ago

6.6.5

3 years ago

6.6.3

3 years ago

6.6.4

3 years ago

6.6.1

3 years ago

6.6.0

3 years ago

6.6.2

3 years ago

6.5.1

3 years ago

6.5.0

3 years ago

6.4.0

3 years ago

6.3.3

3 years ago

6.3.2

3 years ago

6.3.1

3 years ago

6.3.0

3 years ago

6.2.0

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

5.11.0

3 years ago

5.10.0

3 years ago

5.9.0

3 years ago

5.8.2

3 years ago

5.8.1

3 years ago

5.8.0

3 years ago

5.7.0

3 years ago

5.6.4

3 years ago

5.6.3

3 years ago

5.6.2

3 years ago

5.6.1

3 years ago

5.6.0

3 years ago

5.5.4

3 years ago

5.5.3

3 years ago

5.5.2

3 years ago

5.5.1

3 years ago

5.5.0

3 years ago

5.4.1

3 years ago

5.4.0

3 years ago

5.3.10

3 years ago

5.3.9

3 years ago

5.3.8

3 years ago

5.3.7

3 years ago

5.3.6

3 years ago

5.3.5

3 years ago

5.3.4

3 years ago

5.3.3

3 years ago

5.3.2

3 years ago

5.3.1

3 years ago

5.3.0

3 years ago

5.2.1

3 years ago

5.2.0

3 years ago

5.1.1

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.0

3 years ago

4.10.2

3 years ago

4.10.3

3 years ago

4.10.4

3 years ago

4.10.0

3 years ago

4.9.0

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.1

3 years ago

4.6.4

3 years ago

4.6.3

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.12.1

4 years ago

3.12.0

4 years ago

3.11.0

4 years ago

3.10.9

4 years ago

3.10.8

4 years ago

3.10.7

4 years ago

3.10.6

4 years ago

3.10.5

4 years ago

3.10.4

4 years ago

3.10.3

4 years ago

3.10.2

4 years ago

3.10.1

4 years ago

3.10.0

4 years ago

3.9.1

4 years ago

3.9.0

4 years ago

3.8.0

4 years ago

3.7.1

4 years ago

3.6.1

4 years ago

3.6.0

4 years ago

3.5.0

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago