MCPcopy Index your code
hub / github.com/carlini/chess-llm

github.com/carlini/chess-llm @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
318 symbols 969 edges 17 files 284 documented · 89%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ChessLLM

This is a project to play chess against Large Language Models (LLMs). Currently it only supports the OpenAI text completion API, and has only been tested on GPT-3.5-turbo-instruct. (Because this is the only model I've seen that plays chess well.)

This code is very bare-bones. It's just enough to make things run. Maybe in the future I'll extend it to make it better.

If you're reading this and this message is still here, you can play a version of this bot running under my API key by clicking here.

What is this?

This is a chess engine that plays chess by prompting GPT-3.5-turbo-instruct. To do this it passes the entire game state as a PGN, and the model plays whatever move the language model responds with. So in order to respond to a standard King's pawn opening I prompt the model with

[White "Garry Kasparov"]
[Black "Magnus Carlsen"]
[Result "1/2-1/2"]
[WhiteElo "2900"]
[BlackElo "2800"]

1. e4

And then it responds e5 which means my engine should return the move e5.

Installing

This project has minimal dependencies: just python-chess and requests to run the UCI engine, or some additional dependencies to the lichess bot in the lichess-bot folder.

pip install -r requirements.txt
pip install -r lichess-bot/requirements.txt # if you want to run the bot

Getting Started

Add your OpenAI key

Put your key in a file called OPENAI_API_KEY.

UCI engine

If you already have a UCI-compliant chess engine downloaded and want to play against the model you can pass ./uci_engine.py.

Lichess bot

The lichess-bot directory is a fork of the lichess-bot project with a few hacks so that my bot talks a bit more and explains what it's doing. If you want to make a lichess bot, you'll first need to create a new account, then get an API key, and turn it into a bot. The steps to do this are described: in the lichess-bot README.

Once you've done that put your API key as the first line of config.yml.

Next steps

I highly doubt I'll do any of these things, but here are some things I may want to do. (Or you can do!)

  • Search: what happens if instead of predicting the top-1 move you predict different moves and take the "best"? How do you choose "best"?

  • Resign if lost: how can you detect if the game is lost and then just resign if it's obviously over?

  • Other models: right now this works for just OpenAI's text completion models. It would be great to hook this up to other models if any of them become reasonably good at chess.

License: GPL v3

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Core symbols most depended-on inside this repo

set_config_default
called by 81
lichess-bot/config.py
seconds
called by 31
lichess-bot/timer.py
msec
called by 22
lichess-bot/timer.py
to_seconds
called by 19
lichess-bot/timer.py
config_assert
called by 13
lichess-bot/config.py
send_message
called by 12
lichess-bot/conversation.py
is_expired
called by 11
lichess-bot/timer.py
items
called by 10
lichess-bot/config.py

Shape

Method 166
Function 124
Class 28

Languages

Python100%

Modules by API surface

lichess-bot/engine_wrapper.py71 symbols
lichess-bot/lichess-bot.py48 symbols
lichess-bot/lichess.py34 symbols
lichess-bot/model.py33 symbols
lichess-bot/test_bot/lichess.py26 symbols
lichess-bot/matchmaking.py24 symbols
lichess-bot/config.py19 symbols
lichess-bot/timer.py17 symbols
lichess-bot/strategies.py12 symbols
lichess-bot/test_bot/test_bot.py9 symbols
lichess-bot/conversation.py8 symbols
generate_pgn_puzzles.py6 symbols

For agents

$ claude mcp add chess-llm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact