Skip to main content
← projects

Sep 12, 2025

C-hess

Chess implementation in C with SDL2

CSDL2Game Dev

Objective

Build a playable chess game in plain C using SDL2, to sharpen my C skills and get back to basics after years of higher-level languages.

Tools & Technologies

SDL2

Share This

Details

C-hess is a chess game written in plain C with SDL2 for the rendering. After spending most of my time in Laravel and Vue I wanted to get back to basics: manual memory management, pointers, and modelling everything with structs instead of classes.

The board is an 8×8 array of piece structs, each holding a type and a color. Move generation works per piece type: sliding pieces like rooks, bishops and queens cast rays along their axes until they hit something, while knights and kings use fixed offset tables. The result is a list of legal squares for whatever piece you select.

Chess has a surprising amount of special rules that add real complexity: castling (you have to track whether the king and rooks have moved), en passant (a capture that only exists for a single half-move) and pawn promotion. All of those need extra state that lives outside the board array itself. Even a "simple" board game has more rules than you'd think.

While making this project I was reminded how careful you have to be in C. SDL2 textures and surfaces need explicit cleanup, and every allocation is your own responsibility. That was exactly the point of doing it though, and honestly it was a lot of fun.

Source Code


Take a closer look at the source code here: GitHub

Gallery

C-hess board

C-hess board

C-hess board with bishop selected

C-hess board with bishop selected