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: 2722
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