The code template to make a Lichess Bot and deploy it to heroku server easily.
This is the code of @master_bot in lichess.org
- Stockfish 14.1+(dev) POPCNT + SSE41
- v14 Fairy Stockfish POPCNT + SSE41
- book.bin for all chess variants
- heroku/python
- heroku-20 (allowing a maximum hash size of 512 mb)
- Fork this repository.
- Create a new heroku app.
- Go to the
Deploy
tab and clickConnect to GitHub
. - Click on
search
and then select your fork of this repository. - Then
Enable Automatic Deploys
and then select themain
branch (which is already done by default usually) and ClickDeploy
. - Once it has been deployed, go to
Resources
tab on heroku and enableworker (bash startbot.sh)
dynos. (Do note that if you don't see any dynos in theResources
tab, then you must wait for about 5 minutes and then refresh your heroku page.) - Finally go to your
Settings
tab and then underConfig Vars
click onReveal Config Vars
and then in the place ofkey
type inLICHESS_BOT_TOKEN
and in the place ofvalue
add your Lichess Bot Token. - You're now connected to lichess and awaiting challenges! Your bot is up and ready!
Note: Incase of any errors during deploy of code to heroku, make sure to set the buildpack in the 'Settings' tab in heroku as given in the instructions here
- Make sure to disable/switch off the dyno once you are not monitoring your bot, for the bot used to crash in bullet often. In the recent very few games, this stopped happening, but until it is fully tested, switch off the dyno when you are monitoring your bot. If any error shows up in the logs, immediately restart all dynos by more-restart all dynos.
- Also swith off your bot when you are shutting your computer down, else it might crash. This happens due to the bot losing connection with heroku. To prevent this your internet has to be running smoothly and constantly connected to heroku.
- This bot uses 120 MB hash size with 5 threads. This is quite strong, but the downside is games at a time. Heroku's free dyno's limitations are crossed even with 2-3 games in one go. So make sure you don't play many games in one go. If you want multiple games at a time, reduce the values of threads and hash in the lichessbot.py and use multithreading to handle multiple games. This is mainly caused due to rate limiting from heroku or lichess. This can be prevented by increasing 'rate_limiting_delay' in the 'config.yml' file.
- Compared to other bots, this bot plays relatively fast, and the time taken is static. I am trying to figure out a way to have better time management.
- When changing engines make sure you rename your engine name in the
startbot.sh
file, line 2 withchmod a+x engines/engine-name
, whereengine-name
must be replaced with the name of your engine. If your engine name is the same after changing your engine, this doesn't need to be done. Also do note forgot to change the engine name in the config.yml file too, wherename: "sf"
must be changed toname: "engine-name"
, whereengine-name
is the name of your engine. All engines must be placed in the engines folder.