@tahdiislam/chess-play-online

1.3.6 • Public • Published

Chessboard

Easy-to-embed chessboard connected to a chess server.

Ready to npm install:

$ npm i @tahdiislam/chess-play-online

Demo

Setup

Thank you for your interest in this exciting project! Redux Chess is "just a chessboard" as lightweight as it can possibly be. It requires this chess server up and running as well as this chess API.

import React from "react";
import ReactDOM from "react-dom";
import { Chess } from "@tahdiislam/chess-play-online";

/* 

You have to set the playMethod with parameter. You can only set true for one method for one time. If you set one method is true other 3 will be false. You can not set true 2 or more method at one time. Also you can add 4 buttons in you app make it more user friendly.

*/

const props = {
  api: {
    prot: "https",
    host: "pchess.net",
    port: "443",
  },
  server: {
    prot: "wss",
    host: "pchess.net",
    port: "8443",
  },
  playMethod: {
    online: true,
    computer: false,
    playFriend: false,
    enterCode: false,
  },
};

ReactDOM.render(
  <Chess props={props} />,
  document.getElementById("redux-chess")
);

Redux Chess sends messages to a WebSocket server. Make sure the WebSocket server is running on localhost as described next.

$ php cli/wss-server.php
Welcome to PHP Chess Server
Commands available:
/accept {"jwt":"<string>"} Accepts a request to play a game.
/draw {"action":["accept","decline","propose"]} Allows to offer a draw.
/heuristics {"movetext":"<string>"} Takes a balanced heuristic picture of the current game.
/heuristics_bar {"fen":"<string>","variant":"<string>"} Takes an expanded heuristic picture of the current position.
/leave {"action":["accept"]} Allows to leave a game.
/legal_sqs {"position":"<string>"} Returns the legal squares of a piece.
/online_games Returns the online games waiting to be accepted.
/play_lan {"color":"<string>","lan":"<string>"} Plays a chess move in long algebraic notation.
/randomizer {"turn":"<string>","items":"<string>"} Starts a random position.
/rematch {"action":["accept","decline","propose"]} Allows to offer a rematch.
/resign {"action":["accept"]} Allows to resign a game.
/restart {"hash":"<string>"} Restarts a game.
/start {"variant":["960","capablanca80","capablanca100","classical"],"mode":["analysis","gm","fen","pgn","play","stockfish"],"add":{"color":["w","b"],"fen":"<string>","movetext":"<string>","settings":"<string>","startPos":"<string>"}} Starts a new game.
/stockfish {"options":{"Skill Level":"int"},"params":{"depth":"int"}} Returns Stockfish's response to the current position.
/takeback {"action":["accept","decline","propose"]} Allows to manage a takeback.
/undo Undoes the last move.

Listening to commands...

Also, it sends HTTP requests to a REST API that needs to be setup as described in the README.md file.

License

The MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @tahdiislam/chess-play-online

Weekly Downloads

3

Version

1.3.6

License

MIT

Unpacked Size

2.29 MB

Total Files

305

Last publish

Collaborators

  • tahdiislam
  • ashik997