Code Monkey home page Code Monkey logo

baysed-chess's Introduction

Baysed Chess

A Bayesian Approach to Chessbots.

We implement a traditional Monte-Carlo Tree Search (MCTS) and a Bayesian variant inspired by the paper Bayesian Inference in Monte-Carlo Tree Search by Gerald Tesauro, VT Rajan, and Richard Segal. Our implementation is focused on the game chess and designed with flexibility in mind, allowing different strategies to be used in the rollout phase of the MCTS.

Installation

To set up the project, follow these steps:

  1. Install Dependencies

    Ensure that Python 3.11+ is installed on your machine.

    Install Python dependencies with:

    pip install -r requirements.txt

    Note: If not further specified, the commands should be executed in the project's root directory.

  2. Download Chess Engines

    Download Stockfish and unpack it to /stockfish (We use version 16 AVX2). Download Lc0 and unpack it to /lc0 (We use version v0.30.0 DNNL BLAS).

Optionally, if you also want to set up the lichess bot, follow these steps:

  1. Install Local Python Package

    Install the code in /baysed_chess as a local package, so we can use it in the lichess bot files:

    pip install -e .
  2. Set the API Key

    Get an API key from Lichess. Create a copy of the file config.yml.example, located in /lichess_bot. Rename it to config.yml and set token to your API key.

    Note: Lichess requires a separate bot account for bots. More info on the Lichess Wiki on GitHub.

  3. Install Lichess Specific Dependencies

    Install the Python dependencies of the lichess bot by executing in the folder /lichess_bot:

    pip install -r requirements.txt

Main Functionalities

Engine Matches

Let two engines play against each other and collect statistics:

python scripts/main.py --e1 BayesianMCTS --s1 Stockfish --e2 ClassicMCTS --s2 Stockfish -n 24 --proc 12 --time=1 

You can customize with the following command-line arguments:

  • --e1:
    • Engine 1.
    • Possible Values:
      • ClassicMCTS: Our MCTS implementation.
      • BayesianMCTS: Our Bayesian MCTS implementation.
      • Random: Plays completely random.
      • Stockfish: Plays with stockfish.
      • Lc0: Plays with Lc0.
  • --e2:
    • Engine 2.
    • Possible Values: The same ones as Engine 1.
  • --s1:
    • Strategy that Engine 1 uses for the rollout, when set to ClassicMCTS or BayesianMCTS.
    • Possible Values:
      • Random: Play the rollout randomly. Evaluate the terminal state with a simple board evaluation by Tomasz Michniewski.
      • Stockfish: Play the rollout with stockfish. Evaluate the terminal state with stockfish.
      • Lc0: Play the rollout with lc0. Evaluate the terminal state with lc0.
      • RandomStockfish: Play the rollout randomly. Evaluate the terminal state with stockfish.
      • PESTO: Play the rollout according to PESTOs board evaluation. Evaluate the terminal state with PESTOs board evaluation.
  • --s2:
    • Strategy for Engine 2 for the rollout.
    • Possible Values: The same ones as Strategy 1.
  • -n:
    • Number of games to play.
  • --proc:
    • Number of processor cores to use.
  • --time:
    • Amount of seconds each engine has for each turn.
  • --nodes:
    • Number of nodes each engine can compute each turn.
  • --stockfish_elo:
    • Elo for stockfish engine.
    • Default is 1500.
  • --stockfish_path:
    • Path for the stockfish engine executable.
    • Default is /stockfish.
  • --lc0_path:
    • Path for the lc0 engine executable.
    • Default is /lc0.
  • -h:
    • Show the help message.

Web Interface

A web interface for watching two chess engines play against each other:

python scripts/web.py --e1 BayesianMCTS --s1 Stockfish --e2 ClassicMCTS --s2 Stockfish

The web interface should then be up and running at http://localhost:8080. You can customize with the same command-line arguments as main.py.

Board Analyzer

Compare what different engines would do with a given board position. This is quite helpful for analyzing what our implementations do:

python scripts/board-analyzer.py 

Lichess Bot

A bot you can play against on the website Lichess.

Start the bot by running the following in /lichess_bot:

python lichess-bot.py

The bot should then be up and running. You can play against it on the lichess website by searching the bots lichess username and challenging it. The bot might not accept certain challenges e.g. without time constraints. Note: If it's the first time starting the bot, you need to add the -u flag to upgrade your account to a bot account.

The bots code is contained in /lichess_bot and builds upon the repository from lichess-bot. Our implementation is defined in /lichess_bot/homemade.py.

Interactive Geogebra File

A Geogebra file for exploring how to get the minimum and maximum of two gaussian distributions.

You can simply upload the file min_max_of_gaussians.gbb to Geogebra Calculator and try it out.

The following two papers have been quite helpful for this part:

  • Exact Distribution of the Max/Min of Two Gaussian Random Variables by Saralees Nadarajah and Samuel Kotz
  • Speeding up Computation of the max/min of a set of Gaussians for Statistical Timing Analysis and Optimization by Kuruvilla et al.

License

This project is licensed under MIT, except for the code in the folder lichess_bot, which is licensed under AGPL Version 3.

Credits

Lukas Kuess, Theo Haslinger, Stefan Steiniger, Lukas Wieser

baysed-chess's People

Contributors

lukiwieser avatar luk3k avatar dreistein avatar darkcider avatar

Watchers

Kostas Georgiou avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.