Skip to content
forked from xtuml/chess

A modeled application to play chess on lichess.org

Notifications You must be signed in to change notification settings

FMAY-Software/chess

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xtUML chess project

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.

Prerequisites

Download BridgePoint

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.

Create a Lichess bot account

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.

  1. Create a Lichess account for your bot here.
  2. 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.

Fork and clone the repository

  1. If you intend to contribute code or documentation to the project, fork this repository.
  2. Clone (your fork of) this repository.

Maven

Install Apache Maven either through your operating system package manager or by downloading the latest release here

Running the Application

Configuration

  1. Copy lichess_bot/src/main/resources/lichess_bot.properties.template to lichess_bot/src/main/resources/lichess_bot.properties
  2. Edit this file and replace <YOUR_LICHESS_ACCESS_TOKEN> with your API token that you generated earlier.

With xtUML Verifier

  1. Open BridgePoint on a fresh workspace. Import all the projects from the root of the repository.
  2. Build the workspace by either clicking "Build All" in the "Project" menu, or by enabling "Build Automatically".
  3. Switch to the xtUML Debugging perspective.
  4. Select "Run" > "Debug Configurations..." and click on "LichessBot" under the "xtUML eXecute Application" heading.
  5. Click "Debug" to launch the application.
  6. Log in to your human account on lichess.com.
  7. Use the search bar to navigate to the user page for your bot.
  8. Challenge your bot to a match (by clicking on the crossed swords).

With Ciera

  1. Open a terminal and navigate to the root of the repository.
  2. Run the command mvn install
  3. Return to BridgePoint and open the Java perspective.
  4. Select "Run" > "Run Configurations..." and click on "LichessBotJava" under the "Java Application" heading.
  5. Click "Run" to launch the application.

Adding bot intelligence

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.

Interfaces

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.

Utilities

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

Move representation

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.

Extending the application

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.

Chess rules and strategy

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.

Issues

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!

About

A modeled application to play chess on lichess.org

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 87.5%
  • ANTLR 11.8%
  • Shell 0.7%