2.2.4 • Published 1 month ago
chacomat v2.2.4
ChacoMat
A TypeScript chess game.
Create a game
By entering moves
import { ChessGame, coords } from "chacomat";
const game = new ChessGame();
const move_e4 = game.currentPosition.findMoveByNotation("e4");
if (move_e4)
game.playMove(move_e4);
from headers
const spanishGame = new ChessGame({
info: {
White: "Magnus Carlsen",
Black: "Ian Nepomniachtchi",
Result: "*"
},
moveString: "1.e4 e5 2.Nf3 Nc6 3.Bb5 *"
});
from a PGN
const spanishGame = ChessGame.fromPGN(`
[White "Magnus Carlsen"]
[Black "Ian Nepomniachtchi"]
[Result "*"]
1. e4 e5 2. Nf3 Nc6 3. Bb5 *
`);
View Game
PGN
const pgn = game.toPGN();
FEN
const fen = game.currentPosition.toFEN();
board
game.currentPosition.board.log();
/*
8 | r n b q k b n r
7 | p p p p p p p p
6 | - - - - - - - -
5 | - - - - - - - -
4 | - - - - - - - -
3 | - - - - - - - -
2 | P P P P P P P P
1 | R N B Q K B N R
- - - - - - - -
a b c d e f g h
*/
Typings
Types can be imported under the ChacoMat
namespace.
import type { ChacoMat } from "chacomat";
ChacoMat.GameResult; // "1-0" | "0-1" | "1/2-1/2" | "*"
Most components of the game (board, piece, position) can be serialized, for example, to be sent as a JSON response.
// Express server
import { type ChacoMat, Position } from "chacomat";
router.get("/:fen", (request, response) => {
const position = Position.fromFEN(request.params.fen);
response.json(position.toJSON());
});
Customization
Some features of the game can be customized.
import { globalConfig as chacomatConfig } from "chacomat";
chacomatConfig.checkmateSign = "++";
chacomatConfig.castlingCharacter = "O";
Variants
Variants were removed in version 2.0.8 to be re-released as a separate package.
2.2.3
1 month ago
2.2.4
1 month ago
2.2.2
3 months ago
2.2.1
4 months ago
2.2.0
4 months ago
2.1.9
4 months ago
2.1.6
5 months ago
2.1.8
4 months ago
2.1.7
5 months ago
2.1.5
5 months ago
2.1.4
5 months ago
2.1.3
5 months ago
2.1.2
5 months ago
2.0.3
8 months ago
2.1.1
6 months ago
2.0.2
8 months ago
2.0.5
8 months ago
2.0.4
8 months ago
2.0.11
6 months ago
2.0.7
8 months ago
2.0.12
6 months ago
2.0.6
8 months ago
2.0.9
7 months ago
2.0.10
7 months ago
2.0.8
7 months ago
2.1.0
6 months ago
2.0.1
12 months ago
2.0.0
12 months ago
1.3.0
1 year ago
1.2.0
1 year ago
1.1.3
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago