Building My Own Chess Engine – Andrew Healey

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • flask-pgn-api

    python flask api to convert chess single game pgn to mp4 videos and fen to png images

  • I have couple of half built chess projects, you inspire me to complete them

    https://github.com/FossterCare/flask-pgn-api

  • fastchess

    Predicts the best chess move with 27.5% accuracy by a single matrix multiplication

  • For people who'd like the joy of seeing their hobby engine face real people, Lichess has a nice system for verified bot accounts: https://lichess.org/team/lichess-bots

    I'm personally running bits for sunfish https://github.com/thomasahle/sunfish and fastchess https://github.com/thomasahle/fastchess

    There are way too many stockfish clones on there. I hope more hobby chess engine builders will join in.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • pottery

    Pottery - A container and algorithm template library in C (by ludocode)

  • I wrote a toy chess engine a few weeks ago as well as an example for one of my open source libraries [1]. I was inspired by a video of someone writing one in an hour [2], so I also assumed it would take a day or two at most. It took more like a week. But it was very satisfying to not be able to beat my engine anymore.

    I highly recommend that all programmers with even a passing interest in chess spend some time writing an engine.

    [1] https://github.com/ludocode/pottery/tree/master/examples/pot...

    [2] https://youtube.com/watch?v=nzObJ2BpKrk

  • ChessCounter

    Estimate the number of legal chess positions

  • "Claude Shannon calculated that there are around 10^120 possible games of chess in his seminal paper Programming a Computer for Playing Chess in 1950. "

    I've just finished a weekend project to calculate the number of legal chess positions and there are about 8.5E+45: https://github.com/lechmazur/ChessCounter.

    For people considering making a chess program, take a look at this message board http://talkchess.com/forum3/index.php.

  • open-chaos-chess

    Open Chaos Chess is a free and open source version of Chaos Chess, stripped of Google Play Services.

  • There is a funny chess variant on F-Droid called Open Chaos Chess <https://github.com/CorruptedArk/open-chaos-chess> where the players choose what piece should be played but the move is chosen randomly. The first player to lose all pieces loses the game (there are no checks and mates).

  • chessmate

    Chess AI in Java - 2005 High School Project

  • 15 years ago I made a simple alpha-beta minimax chess engine for a high school Java project. 10 years later it was used in a Minecraft mod called MineChess: https://github.com/theronic/chessmate

  • Stockfish

    A free and strong UCI chess engine

  • For what it's worth, there is a pretty solid conventional wisdom in this space.

    > - A simpler but much faster engine will beat a more complex engine any time because the advantage of another ply easily outweighs the advantage of some clever algo.

    Depends a lot on what you call "simple". Stockfish's search and evaluation subroutines are pretty complex and distinctly clever:

    https://github.com/official-stockfish/Stockfish/blob/master/...

    https://github.com/official-stockfish/Stockfish/blob/master/...

    But I agree that early on, simple is the way to go. It's much easier to optimize a simple engine.

    > - A 10x10 board with an unreachable edge has some advantages [...]

    Maybe in theory, but FWIW I don't know of any modern engine that does this. A more popular variant of the 10x10 or 10x12 idea was, back in the day, the 0x88 layout:

    https://www.chessprogramming.org/0x88

    If you're going to be writing an engine today from scratch, use the bitboard representation. It's easy to implement and has the most resources out there if you need help.

    (Bitboards is just the idea of representing the game state as a bunch of 64-bit ints, with one u64 per white/black type of piece.)

    Your example use-case, of knight posisitions, is usually solved with bitboards using an 64-element array mapping squares to a bitboard of all the places a knight on that square can go. Here's where Stockfish does that:

    https://github.com/official-stockfish/Stockfish/blob/b06ef36...

    Other commenters have noted that you can do a slightly fancier version of this lookup table technique to solve for the sliding pieces (bishops and rooks (queens are a bitwise OR of bishops and rooks)), because the raw data is low entropy, so finding a perfect hash function ("magic bitboard", in the lingo) is fast enough to do on startup:

    https://github.com/official-stockfish/Stockfish/blob/b06ef36...

    It's existing techniques like this that make bitboards a good choice for beginners; if you get stuck, you can find resources online.

    > - Optimization of engine code is much harder than optimization of the yield function.

    Big +1 there! The yield function is also much easier to A/B test.

    > - It is much better to not generate 'bad' moves than it is to prune them away after a lot of extra work has been done. Colin Wrights' law: 'You can't make computers faster, you can only make them do less work' clearly applies here.

    Yes, but it's pretty hard to reliably get your move generator to generate good moves first. The other side of making mixmax search fast is quickly throwing out branches that aren't relevant.

    For instance, delta pruning and null-move pruning do this by trying to detect if one of the sides has thrown the game with their last move; since minmax is about assuming optimal play on both sides, branches where someone makes a blunder aren't worth looking into.

    > - memoization can bring insane speed gains.

    Yup! Also, a lot of engines have optimized routines that let you undo a move quickly, without having to keep a redundant stack of every position's state, which would involve a lot of memcpy-ing.

    Have fun! I had to stop doing chess engines, they were becoming too much of a distraction for me. I'm kind of glad ML-AI is starting to beat human-crafted AI in chess, that way the space can go back to being a fun little hacker cottage industry.

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Grandmaster-Level Chess Without Search

    1 project | news.ycombinator.com | 9 Feb 2024
  • Interested in going to my first tournament and was wondering if there is a place where I can review players classical games around 1700 rating so I can get an idea of what is expected and their strengths?

    1 project | /r/chess | 16 Jun 2023
  • Scientists claim >99 percent identification rate of ChatGPT content

    1 project | news.ycombinator.com | 8 Jun 2023
  • Most human engine to play against?

    1 project | /r/chess | 18 May 2023
  • Do you have to buy Maia to use it offline?

    2 projects | /r/chess | 11 May 2023