Projects

Chal

A complete, FIDE-rules-compliant chess engine written in 934 lines of C with zero external dependencies and an embedded neural network (NNUE).

The name is Gujarati for “move” or “tactic.” The project started as a personal challenge: build a clean, readable chess engine that fits entirely under 1,000 lines of standard C without cutting corners on rules or performance.

In version 2.0, the engine was rewritten from scratch—moving from the original 0x88 board representation to bitboards, magic attack lookups, and an embedded dual-perspective NNUE trained on 35 million positions of self-play data. Despite adding a neural evaluation, the entire codebase shrank to 934 lines, achieved a 5x speedup (~4 million nodes/sec), and reached an estimated rating of ~3100 Elo.

Design & Architecture

  • Strict FIDE Compliance: Minimalist engines frequently cut corners. Chal doesn’t. It handles en passant, all three underpromotions (knight, bishop, rook), full castling rights with safety verification, repetition detection, the 50-move rule, and draw by insufficient material.
  • Modern Core: Bitboard board representation, magic attack tables for sliding pieces, and a unified pseudo-legal move generator.
  • Embedded NNUE: A dual-perspective (768 -> 32) x 2 -> 1 network with clipped squared ReLU activations, evaluated directly on CPU integers without external weight files or libraries.
  • Search: Negamax with Alpha-Beta, Principal Variation Search (PVS), iterative deepening, aspiration windows, a 16MB transposition table, and search pruning heuristics (null move pruning, reverse futility pruning, history heuristics, and late move reductions).
  • Readable by Design: The single source file (src/chal.c) is split into 8 linear sections with explanatory comments, organized to be read top-to-bottom in a single sitting without forward declarations.

Source code: github.com/namanthanki/chal