How to Program a Chess Engine in Lisp

:: programming, racket, artificial intelligence, lisp, scheme

Last updated 2024–11–29 18:48

Table of Contents

  1. The Chess Piece
  2. The Chess Board
  3. FEN - Forsyth-Edwards Notation
  4. The Chess Move
  5. Move Generation

Introduction

Programming a competent chess engine in lisp has been a goal of mine for some time. I finally did so in 2021, and it was a lot of fun! My new goal is to rewrite the code in a step by step way that emphasizes clarity, and to present it as a clear tutorial for writing a chess engine, and as a general Racket tutorial.

This post is the beginning of that journey, and will be updated as a table of contents for the entire series as each post is written. I’ll also be updating this header post with links to resources as we go along. I’m hoping to complete the series by the end of this month (November 2024).

The best way to contact me is probably via:

Source

RacketChess github repository

Goals

The primary goal of this project is to provide a clear, understandable tutorial on how to write a chess engine in the Racket programming language. A secondary goal is to find a sweet spot in the tension between clarity and competitiveness, so that the engine can play at a reasonable intermediate level while still being very understandable. My current rating on lichess.org is roughly 1,700 for blitz chess, so the engine should easily beat me if successful. If you’re a more talented chess player, you may need to add additional functionality for the engine to beat you :)

The resulting chess engine will not be competitive with world class chess engines for two reasons:

  • The optimizations required to be competitive obfuscate the code too much for our purposes.
  • Racket is not close enough to the speed of C++ to be competitive.

Racket

You can obtain the Racket programming language here

Contributions

Once the initial tutorial is completed, there will be opportunity for additional functionality. I’d like to leave the original repository in place for pedagogy purposes, but we can refine and optimize a fork to be more competitive if that is of interest to folks.

Resources