Skip to content

shashankp28/mystic-bot

Repository files navigation

Mystic Chess Bot

Mystic bot (Generated By MetaAI)

Tests Passing GitHub Contributors Issues GitHub pull requests OpenSSF Scorecard

A simple yet powerful Chess Bot written in Rust, designed for efficiency and scalability.

The bot currently has an account on Lichess: MysticBot.

⚠️ Note: The bot is not running constantly due to budget constraints.

Getting Started

  1. Clone the Repository
    Start by cloning the repository to your local system:

    git clone https://github.com/shashankp28/mystic-bot.git
  2. Install Python Dependencies
    Ensure you have Python installed, then install the required dependencies:

    pip install -r requirements.txt
  3. Build the Bot Using Cargo
    Use cargo to build the bot for optimized performance:

    cd mystic-bot
    cargo build --release
  4. Run the Bot Independently
    After building, you can start the RestAPI server for the engine directly:

    cargo run -- --port <port>  # or
    ./target/release/mystic-bot --port <port>

    Bot Running Example

  5. Configure Lichess API Key
    To connect the bot to your Lichess account:

    • Open the config.yml.default file.
    • Replace the placeholder xxxxxxxxxxxxxxxxxxxxxx with your Lichess API key:
      token: "your_lichess_api_key"
    • Rename the file to config.yml and make the necessary changes:
      mv config.yml.default config.yml
    • Run the bot using the following command:
      python lichess-bot.py -u

Follow these steps to set up and enjoy playing with Mystic Chess Bot! ♟️✨

API Docs: Postman

Bot Overview

The engine uses Rust chess chrater to generate moves

1. Opening Database

  • The bot uses an opening database containing 0.8 million+ chess positions.
  • For the first few moves, the bot looks up this database to instantly play the best-known responses.
  • This enables quick and accurate moves in the opening phase, saving computation time for later stages of the game.

2. Search Algorithm

The bot implements a search algorithm using a combination of:

  • Dynamic time keeping: Plays slower if more time is available, and faster if less
  • Iterative Deepening: Calculates different depths based on time available
  • Alpha-beta pruning: Prunes unnecessary branches in the search tree.
  • Move Ordering: Orders moves based on checks / captures / attacks / castle, to aid AB pruning
  • Quiet Search: Run search until position is not noisy, before static eval
  • Bonus: Static bonus such as: Double Bishop, connected pawns, passed pawns, etc.
  • Penalty: Static penalty such as: doubled pawns, king cornered, etc.

Key features:

  • Evaluates 300,000+ positions per second on an average.
  • Evaluates to 5-6+ positional game depth.
  • Evaluates 5-6 noisy depth, using quiet search
  • Multi-threading to evaluate multiple positions in parallel
  • Dynamically adjusts search depth:
    • Midgames: Searches to a depth of 5–6 moves.
    • Endgames: Increases search depth to 10-11 moves.

3. Heuristics

The evaluation function combines:

  • Static piece values: Assigns scores to pieces (e.g., Pawns, Knights, Bishops, etc.).
  • Positional values: Evaluates the strategic placement of pieces on the board.

For reference, the scoring is inspired by this website.

⚠️ Currently, the bot does not use neural networks and hence does not learn from games. Future work may include integrating a learning-based system to enhance performance.

4. Future Enhancements

  • Neural Network Integration: To enable adaptive learning and improve decision-making
  • Endgame Tablebases: For perfect endgame play
  • Better Algorithm: Better evaluation function, better search algorithm
  • Cross-Platform Support: Ensuring compatibility across Windows, Linux, and macOS

Contact

For any inquiries or support, feel free to reach out to: shashankp2832@gmail.com / anandishegde@gmail.com

License

Mystic Bot is licensed under the MIT License.
You can check out the full text of the MIT License in the LICENSE file.

Additionally, this project may include code from Lichess Bot, which is also licensed under the AGPLv3.
Please refer to the Lichess Bot LICENSE for more information.

Packages

No packages published

Contributors 2

  •  
  •