This project creates a simple chess bot using javascript that connects to lichess' bot interface https://lichess.org/api#tag/Bot . This project can be hosted free on cloud providers such as render.com.
- Play against this bot unrated now on lichess at @bot-o-tron
- Get an API token from lichess.org and add it as an environment variable on your machine or cloud hosting provider.
$ nvm use v18.16.1
$ yarn install
# Linux
$ export API_TOKEN=xxxxxxxxxx
# Windows
$ setx API_TOKEN xxxxxxxxxx
The project runs as an express node server that connects to the lichess BOT account using the API_TOKEN
yarn start
yarn test
To implement your chess bot you only need to create one class that implements the method:
getNextMove(moves) {
return uciMove;
}
Where moves is a list of moves so far in uci format e.g. ["e2e4", "b8c6", "f2f4"]
See RandomPlayer
for minimal implementation
using chess.js
If you register a free render.com account you can host a BOT like this one
as is - just add your API_TOKEN
to the environment property configuration.
This code auto deploys and is live at https://bot-o-tron.onrender.com/
Compare bots locally in a round-robin tournament
$ yarn tournament
Results
[ { player: 'AntiPatzerPlayer ', score: 32.5 },
{ player: 'PatzerPlayer ', score: 23 },
{ player: 'RandomPlayer ', score: 22.5 },
{ player: 'SwarmKingPlayer ', score: 18 } ]