Sep 12, 2025
C-hess
Chess implementation in C with SDL2
Objective
Implement a playable chess game in plain C using SDL2, as a deliberate exercise in low-level thinking, manual memory management, and getting back to basics after years of higher-level languages.
Tools & Technologies
SDL2
Details
C-hess is a chess implementation written in plain C with SDL2 for rendering. The motivation was straightforward: I wanted to sharpen my C skills and work on something non-trivial enough to force engagement with the parts of C that higher-level languages abstract away: manual memory management, pointer arithmetic, struct-based data modelling without classes.
The board is represented as an 8×8 array of piece structs, each holding type and color. Move generation is handled per piece type: sliding pieces (rooks, bishops, queens) use ray-casting along their valid axes and stop on collision; knights and kings use fixed offset tables. The result is a list of legal destination squares for any selected piece.
Chess has a handful of special-case rules that add real complexity: castling (requires tracking whether king and rooks have moved), en passant (a capture that only exists for one half-move after a double pawn push), and pawn promotion. Each of these needs state that lives outside the board array itself, a good reminder that even "simple" games have non-trivial rule surfaces.
Working in C without a garbage collector means thinking carefully about every allocation. SDL2's texture and surface lifecycle requires explicit cleanup, and move lists are allocated on the stack where possible to avoid leaks. The discipline of it is the point. After spending most of my time in Laravel and Vue, coming back to C is a useful reset.
Source Code
Source available on GitHub.
Gallery

C-hess board

C-hess board with bishop selected


