rsg-chess

1.1.0-alpha.2 • Public • Published

RSG-Chess-API

Chess APIs based on RSG Chess

Installation

// via NPM
npm install rsg-chess
// via Yarn
yarn add rsg-chess
// via CDN
<script src="https://storage.googleapis.com/rsg-chess-api/cdn/index.min.js">

Usage

Import the modules

// ES6
import { Game, AI, Pieces, tools } from "rsg-chess";
 
// NodeJS
const { Game, AI, Pieces, tools } = require("rsg-chess");
 
// CDN
// The `RSGChess` global variable can be used once, after all scripts have loaded successfully
var Game = RSGChess.game;
var AI = RSGChess.AI;
// ect.

Use the functions

To use our API take a look at the docs and the supported functions!

Example:

// ES6
const game = Game.prototype.initializeGame();
game.moveSelected(
  game.board[6][0], { y: 5, x: 0 }, () => {}, () => {}, false, false
)
...
 
// Node.JS
const game = RSGChess.Game.prototype.initializeGame();
game.moveSelected(
  game.board[6][0], { y: 5, x: 0 }, () => {}, () => {}, false, false
)
...
 
// Standard JS
var game = RSGChess.Game.prototype.initializeGame();
// RSGChess is a global variable
game.moveSelected(
  game.board[6][0], { y: 5, x: 0 }, () => {}, () => {}, false
)

Releases and changelog

Docs

Documentations, Get Started guides and tutorials are available on http://rsg-chess.now.sh/docs/api/

Note that the docs are not completed yet and may contain wrong links and broken demos.

Supported functions

Game logic and controls

  • new Game (promoCallback)
  • Game.prototype.initializeGame
  • Game.prototype.piece (type, x, y, color)
  • Game.prototype.moveSelected (selected, to, promotionCallback, checkmateCallback, simulate)
  • Game.prototype.promotePawn (pawn, x, y, color, type)
  • Game.prototype.simulateAndFilter (moves, piece)
  • Game.prototype.checkmate (color)
  • Game.prototype.simpleMovePiece (piece, from, to)
  • Game.prototype.warning (color)
  • Game.prototype.allMoves

notations and rules

  • Game.prototype.threefoldCheck
  • Game.prototype.halfmoveClock
  • Game.prototype.castlingTarget
  • Game.prototype.enPassantTarget
  • Game.prototype.fullmoveCount
  • Game.prototype.pieceToAN (x, y)
  • Game.prototype.boardToFEN
  • Game.prototype.activeColour
  • Game.prototype.gameToFEN

Game.prototype variables

  • game.board
  • game.turn
  • game.threefold
  • game.FEN and game.FENboard

AI

  • The AI method.
    • syntax and input: AI(depth, gameState, isMaximisingPlayer)
    • output: bestmove { from, to }

Tools

Sometimes you need to manage a lot of different indications such as app performance, AI speed, bundle file size, battery life and more. That's why we've added tools to RSG Chess API as built-in methods or external plugins. With them you can run more complex tasks (transfer data from/to servers/back-ends, using workers and threads or databases), manage the performance and improve the speed of the app.

  • uncycleBoard(boardObject)
  • uncycleTurns(turnObject)

These two methods remove the cyclic game references from the board and turn objects so you can stringify them, send via HTTP requests or even save as cookies for later usage.

This API is officially powering the RSG Chess mobile app and the rest of the "RSG Chess family"

Additional links

Package Sidebar

Install

npm i rsg-chess

Weekly Downloads

3

Version

1.1.0-alpha.2

License

Apache-2.0

Unpacked Size

392 kB

Total Files

17

Last publish

Collaborators

  • ibujs
  • radi-cho