Chal - complete FIDE-rules chess engine in 776 lines of C90

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

namanthanki
Posts: 10
Joined: Wed Mar 04, 2026 12:39 pm
Full name: Naman Thanki

Chal - complete FIDE-rules chess engine in 776 lines of C90

Post by namanthanki »

I wrote a small chess engine called Chal.

The goal was to build a complete classical engine while keeping the code as small and readable as possible. The entire engine is 776 lines of C90 in a single file, with no dependencies.

Despite the size it implements the full set of FIDE rules and passes the standard perft tests, including:
  • en passant and all underpromotions
  • correct castling-rights handling when a rook is captured
  • repetition detection
  • correct stalemate and checkmate reporting
The engine's search stack includes:
  • negamax
  • iterative deepening
  • aspiration windows
  • null-move pruning
  • late-move reductions
  • quiescence search
  • transposition table
  • triangular PV table
It implements UCI properly (streams `info depth … score … pv`, handles `ucinewgame`, etc.) and includes a simple time manager.

The main purpose of the project is readability. The whole engine can be read top-to-bottom as a single file, with comments explaining each subsystem.

I don't have a formal Elo measurement yet. In informal testing against engines like TSCP 1.81, MicroMax 4.8, and BBC 1.2, it appears to play roughly around the ~1800 level, particularly at shorter time controls.

It would be interesting to see how it performs in CCRL.

Source:
https://github.com/namanthanki/chal
Windows and Linux builds are available in the releases section.

I'm also curious which parts of the code people find most confusing or unclear.
The goal is for the whole engine to remain readable in a single sitting.
User avatar
chrjly2
Posts: 26
Joined: Sat Aug 31, 2024 7:15 pm
Full name: Christophe Jolly

Re: Chal - complete FIDE-rules chess engine in 776 lines of C90

Post by chrjly2 »

Thanks. The explanations seem correct. 776 lines is very short.
namanthanki
Posts: 10
Joined: Wed Mar 04, 2026 12:39 pm
Full name: Naman Thanki

Re: Chal - complete FIDE-rules chess engine in 776 lines of C90

Post by namanthanki »

chrjly2 wrote: Sat Mar 07, 2026 5:24 pm Thanks. The explanations seem correct. 776 lines is very short.
There are a few changes I'm planning to work on, will prolly move from C90 to C99 so I can use proper 64bit zobrist hashing. Discovered some bugs during testing that I want to fix. The engine will probably grow by some lines as I make these improvements, and then I plan to freeze it once it plays reliably well. Thanks for taking the time to check it out!
Aleks Peshkov
Posts: 993
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia
Full name: Aleks Peshkov

Re: Chal - complete FIDE-rules chess engine in 776 lines of C90

Post by Aleks Peshkov »

Good job. I appreciate volume of comments. Matter of taste but single code file C90 program is a strange choice for readability.
IMO HCE is overcomplicated for a simple program, but otherwise good set of features.
namanthanki
Posts: 10
Joined: Wed Mar 04, 2026 12:39 pm
Full name: Naman Thanki

Re: Chal - complete FIDE-rules chess engine in 776 lines of C90

Post by namanthanki »

Aleks Peshkov wrote: Sat Mar 07, 2026 8:42 pm Good job. I appreciate volume of comments. Matter of taste but single code file C90 program is a strange choice for readability.
IMO HCE is overcomplicated for a simple program, but otherwise good set of features.
Hello Aleks!
Thanks for the kind words and you're right about putting everything in a single file but this was started with the intent to keep it simple and didactic and under 1k LOC max so yeah that's the decision behind it, other than that will be migrating to C99 soon! and also you're right about HCE being complicated... I am just going to switch to pesto in the next major release.