This project provides a framework for creating bots to play chess on lichess.org. The project provides bindings to the Lichess public API as well as management of challenges and games and a utility for listing legal moves. The project is set up to run in BridgePoint Model Verifier.
Download the latest version of BridgePoint from here. Due to ongoing development related to this project, an engineering branch build is required to run the project.
To get started, you must create an account on lichess.org. In accordance with Lichess terms of service, an account must not have played any games before being converted to a bot account. The first time you run the application, your account will automatically be upgraded to a bot account. Note that you will not be able to use a bot account to play normally on the site after it has been upgraded. We recommend that you create two accounts -- one for the bot and one to play as a human player.
- Create a Lichess account for your bot here.
- Once logged in, follow this link to generate an API token for your bot. Save the token in a secure location. Do not commit it to the repository.
- If you intend to contribute code or documentation to the project, fork this repository.
- Clone (your fork of) this repository.
Install Apache Maven either through your operating system package manager or by downloading the latest release here
- Copy
lichess_bot/src/main/resources/lichess_bot.properties.template
tolichess_bot/src/main/resources/lichess_bot.properties
- Edit this file and replace
<YOUR_LICHESS_ACCESS_TOKEN>
with your API token that you generated earlier.
- Open BridgePoint on a fresh workspace. Import all the projects from the root of the repository.
- Build the workspace by either clicking "Build All" in the "Project" menu, or by enabling "Build Automatically".
- Switch to the xtUML Debugging perspective.
- Select "Run" > "Debug Configurations..." and click on "LichessBot" under the "xtUML eXecute Application" heading.
- Click "Debug" to launch the application.
- Log in to your human account on lichess.com.
- Use the search bar to navigate to the user page for your bot.
- Challenge your bot to a match (by clicking on the crossed swords).
- Open a terminal and navigate to the root of the repository.
- Run the command
mvn install
- Return to BridgePoint and open the Java perspective.
- Select "Run" > "Run Configurations..." and click on "LichessBotJava" under the "Java Application" heading.
- Click "Run" to launch the application.
The template project provides the minimum amount of intelligence to play a game. On its turn, the bot will select a random move from the list of legal moves and play that move. It is the task of the modeler to improve this behavior to create a winning strategy.
The chess
interface provides a modeled hook into the lichess.org public API.
For more information on this API, visit the Lichess documentation page
here. Messages and types were modeled to closely
follow this reference.
The ChessLib
utility has been provided with the legalMoves
bridge. This
bridge takes as input an array of moves that have occurred in the game since
the start position. It returns an array of legal moves.
This section is a work in progress
Each move is represented by a 4 character string in Long Algebraic Notation -- a four character string in which the first two characters represent the file (column) and rank (row) on which the moved piece started and the last two characters represent the file and rank on which the moved piece completed its move. In standard chess vocabulary, a move represents a move by white and a corresponding response by black. In the model, however, each move by black or white is represented as its own element in the array of moves representing the state of the game. A natural consequence of this fact is that if the length of the move array is divisible by 2, it is white's turn to play. If the array is not divisible by 2, it is black's turn to play.
The application consists of two components -- Engine
and Lichess
. The
Lichess
component is a realized component and should not be edited by the
modeler.
The modeler has freedom to extend the application as desired. A natural
starting place is the "our turn" state within the Game
instance state machine
in the Engine
component. Here the bot must select the next move and then
generate the "play move" event.
lichess.org requires bots to play according to standard chess rules. The moves
returned by the ChessLib
EE will also observe the rules and only return legal
moves. Any move selected by a bot to play next should be one of these legal
moves.
An excellent resource for learning the rules and some basic bot strategies is the Chess Programming Wiki found here. The official rules of chess can be found here.
If you are having an issue with BridgePoint or Verifier, please check the issue tracker to see if the behavior matches an existing issue. This custom query has been created to track issues specifically relating to this modeling challenge. If you don't find the issue you are looking for, please raise a new issue here.
If you have an issue (bug, new feature, etc) with the xtuml/chess project itself, raise an issue in the repository tracker. Of course pull requests with fixes and improvements are welcome!