🤖 A Customizable Python Chess Bot
This is a simple python script that listens to the Event stream for a Lichess.org BOT account and accepts/rejects challenges, plays games using fully customizable engine, responds to users in the game's chat.
There is already a sample chessbot implementation RandomMoveBot() which randomly plays a legal move.
This project was made using berserk-downstream. A client library for the Lichess API
Check out my BOT account you can play against here.
Make sure you have a Lichess account that you have upgraded to a BOT account and created a PAT for your account
First clone the repository:
git clone https://github.com/Rowan441/WeirdChessBot.git
Then install virtualenv if you don't already have it:
pip install virtualenv
cd into the project directory and create a virtual environment:
virtualenv .venv
Activate the virtual enironment:
On windows:
.venv\Scripts\activate
On Unix / MacOS:
source .venv/bin/activate
Finally install the required libraries:
pip install -r requirements.txt
Important: you need to create a file named api.token
in the root directory of the project add your BOT account's Personal API token to the file
echo YOURAPITOKEN > api.token
To run the project make sure you have a Lichess account that you have upgraded to a BOT account and added your API token to a api.token file
Run the starterlichessbit.py
file with optional --logfile
flag:
starterlichessbot.py
OR
starterlichessbot.py --logfile ..\logs.txt
You can create your own Bots. In this program, a Bot is defined as a class that implements: getBestMove(self, gameState, variant)
and getResponseToMessage(self, chatLine)
methods
Checkout the ChessBotInterface()
class in the chessbots.py
file for the specific details of the getBestMove and getResponseToMessage functions. You can create subclasses from ChessBotInterface()
and override its methods with your own funcitonality.
Once you have a working bot you can tell the program to use it by:
- Importing the bot in
starterlichessbot.py
:
8| from chessbots import MyBotClass # Import your bot
- instantiating the bot on line 17 of
starterlichessbot.py
19| bot = MyBotClass()
In the source code this has already been done with RandomChessBot
, so just replace RandomChessBot
with your bot class.
- Python
- berserk-downstream - Lichess Client Library
- python-chess - Python Chess Library