PHP Ratchet WebSocket server using PHP Chess. The chess server is intended to connect to a Redux Chess app.
Clone the chesslablab/chess-server
repo into your projects folder as it is described in the following example:
$ git clone git@github.com:chesslablab/chess-server.git
Then cd
the chess-server
directory and install the Composer dependencies:
$ composer install
Create an .env
file:
$ cp .env.example .env
Run all the tests
$ composer test
Start the server:
$ php cli/ws-server.php
Welcome to PHP Chess Server
Commands available:
/accept {"id":"id"} Accepts a friend request to play a game.
/ascii Prints the ASCII representation of the game.
/castling Gets the castling status.
/captures Gets the pieces captured by both players.
/draw {"action":["accept","decline","propose"]} Allows to offer a draw.
/fen Prints the FEN string representation of the game.
/heuristicpicture Takes a balanced heuristic picture of the current game.
/history The current game's history.
/ischeck Finds out if the game is in check.
/ismate Finds out if the game is over.
/piece {"position":"string"} Gets a piece by its position on the board.
/pieces {"color":["w","b"]} Gets the pieces on the board by color.
/playfen {"fen":"string"} Plays a chess move in shortened FEN format.
/quit Quits a game.
/resign {"action":["accept"]} Allows to resign a game.
/start {"mode":["analysis","loadfen","playfriend"],"fen":"string","color":["w","b"],"min":"int"} Starts a new game.
/status The current game status.
/takeback {"action":["accept","decline","propose"]} Allows to manage a takeback.
/undomove Undoes the last move.
Listening to commands...
Open a console in your favorite browser and run commands:
const ws = new WebSocket('ws://127.0.0.1:8080');
ws.onmessage = (res) => { console.log(res.data) };
ws.send('/start analysis');
Before starting the secure WebSocket server for the first time, make sure to copy the
certificate.crt
andprivate.key
files into thessl
folder as explained in A Simple Example of SSL/TLS WebSocket With ReactPHP and Ratchet.
Start the server:
$ php cli/wss-server.php
Open a console in your favorite browser and run commands:
const ws = new WebSocket('wss://pchess.net:8443');
ws.onmessage = (res) => { console.log(res.data) };
ws.send('/start analysis');
The MIT License.
See the contributing guidelines.
Happy learning and coding! Thank you, and keep it up.
For further information you're invited to read my learning journey:
- Demystifying AI Through a Human-Like Chess Engine
- Two Things That My AI Project Required
- What Are Some Healthy Tips to Reduce Cognitive Load?
- How to Take Normalized Heuristic Pictures
- Equilibrium, Yin-Yang Chess
- Adding Classes to a SOLID Codebase Without Breaking Anything Else
- Preparing a Dataset for Machine Learning With PHP
- Converting a FEN Chess Position Into a PGN Move
- A React Chessboard with Redux and Hooks in Few Lines
- How to Test a Local React NPM Package With Ease
- TDDing a React App With Jest the Easy Way
- How to Test React Components With Joy
- My First Integration Test in a Redux Hooked App
- Creating a Local WebSocket Server With TLS/SSL Is Easy as Pie
- A Simple Example of SSL/TLS WebSocket With ReactPHP and Ratchet
- Newbie Tutorial on How to Rate-Limit a WebSocket Server
- Visualizing Chess Openings Before MLP Classification