After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
rebitz42
Posts: 1
Joined: Fri Dec 19, 2025 7:47 pm
Full name: Joe-Manuel Schlüter

After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Post by rebitz42 »

Hey everyone,

Lately I’ve been getting really curious about how chess engines work. I’m still a novice programmer, so I decided to use a few tools to help me get something working without getting overwhelmed.

I used chess.js and chessboard.js to handle the basics, and implemented minimax with alpha-beta pruning, based on what I read online. The goal was mainly to learn, not to build anything strong or optimized.

I know this is far from the best chess engine out there, but I’m honestly pretty proud of finishing it, and I wanted to share it here in case anyone finds it interesting (or has advice).

Here’s the project:
https://github.com/rebitz42/leepawn

Thanks for reading!
Robert Pope
Posts: 570
Joined: Sat Mar 25, 2006 8:27 pm
Location: USA
Full name: Robert Pope

Re: After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Post by Robert Pope »

Congratulations!

One of the most important elements of a chess program is that it can recognize all legal moves. If you haven't already, implement the perft command, and validate that you generate the proper number of possible moves from several positions (kiwipete is a famous one, as well as the start position).

It's really common for a new program to miss edge conditions - e.g. an en passant capture that would create a discovered check on your king, or castling when the rook has moved away from and back to H1.
User avatar
Ras
Posts: 2735
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Post by Ras »

Robert Pope wrote: Sun Jan 04, 2026 6:18 pmcastling when the rook has moved away from and back to H1.
I once had a bug where where capturing a castling enabled rook and then recapturing with another rook would register the recapturing castling rook still as castling enabled - because only moving the rook away was counted as lost castling right.

[d]1k6/1b6/8/7R/8/8/8/4K2R b K - 0 1

1. ... Bxh1
2. Rxh1 Kb7
3. 0-0 (bug)
Rasmus Althoff
https://www.ct800.net
User avatar
jshriver
Posts: 1372
Joined: Wed Mar 08, 2006 9:41 pm
Location: Morgantown, WV, USA

Re: After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Post by jshriver »

Robert Pope wrote: Sun Jan 04, 2026 6:18 pm Congratulations!

One of the most important elements of a chess program is that it can recognize all legal moves. If you haven't already, implement the perft command, and validate that you generate the proper number of possible moves from several positions (kiwipete is a famous one, as well as the start position).

It's really common for a new program to miss edge conditions - e.g. an en passant capture that would create a discovered check on your king, or castling when the rook has moved away from and back to H1.
I just recently came across kiwipete. Do you know of other good known perft positions like that?
gflohr
Posts: 85
Joined: Fri Jul 23, 2021 5:24 pm
Location: Elin Pelin
Full name: Guido Flohr

Re: After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Post by gflohr »

mathmoi
Posts: 291
Joined: Mon Mar 13, 2006 5:23 pm
Location: Québec
Full name: Mathieu Pagé

Re: After 13 Hours (with breaks), I Finally Finished My Tiny Chess AI

Post by mathmoi »

jshriver wrote: Wed Jan 28, 2026 9:02 am I just recently came across kiwipete. Do you know of other good known perft positions like that?
Here is a list of simple positions that each test a specific condition. When developing my last engine, once all theses positions returned the correct results my perft was also returning correct results.

There is a python script in the repo (https://github.com/mathmoi/ChessMoveTestsGenerator) that can use this file and generate a large file with lots of informations for each positions, including all the move that can be played in the position and the resulting FEN of playing that move.

See here (https://github.com/mathmoi/oxide9/blob/ ... r_tests.rs) how I used this file in my chess engine to test move generation, make, unmake, uci move serialization and parsing.