Martuni — How I Started Building a Chess Engine
I’ve loved and played chess for as long as I can remember. Not well, not badly — somewhere in the middle, where you know enough to suffer but too little to consistently improve. My actual playing strength bears no relation to my dedication to the game.
But what this is really about is my long-standing desire to build my own chess engine. I’m finally doing it. The next few posts will chronicle that journey.
The Idea
The plan started small: write a simple UCI engine in Rust. UCI is the protocol through which chess interfaces communicate with engines — the standard that Stockfish, Leela, and all the others speak. If my engine understands it, I can plug it into any GUI, run it on my server, play against myself.
Rust was the choice because I wanted to learn it. Not because I knew it. I know C, have for a long time — ANSI C — but Rust I still have to learn. Trust me though: in 2026, you don’t start anything new in C.
The name came quickly: Martuni. Sounds good. It’s a place in Armenia that means something to me. And it was available — as a Lichess username, as a domain. I’ll let slip where we’ll be two or three posts from now: the engine is still in development, but you can already play it on Lichess. I’ve wrapped it in a bot for that purpose. Right this way, if you’d like to challenge it to a game.
The First Commit
The first real commit was on the evening of April 9th. The engine played random legal moves.
That sounds like little. It was enormous.
Because behind “knowing legal moves” lies the entire rulebook: check, castling, en passant, stalemate, draw by repetition. I could have implemented all of that by hand — and I’d still be at it today. Instead I chose an existing crate: chess by Jordan Bray. It handles board representation and move generation. Everything else — the logic of what the engine decides — that’s my own work. That’s what I want to do: build a chess engine that may not come close to matching Stockfish, but is mine. At least in its core, in its algorithms.
I made that choice deliberately. A chess engine isn’t a competition in bitboard arithmetic. It’s the search and evaluation algorithm.
So the first version could already play chess, in the literal sense. It just had no idea what it was doing.
Alpha-Beta: The Heart of It
A day later, on April 10th, came the step that turns a random engine into a thinking one: alpha-beta search with quiescence and a transposition table.
Alpha-beta is an algorithm that dramatically reduces the search space of a chess tree. The core idea is that you prune branches the moment you know they’re worse than what you’ve already found. What’s remarkable: optimal play is preserved. You only cut away the obvious garbage.
Added to that is iterative deepening — the engine searches to depth 1, then 2, then 3, and so on until time runs out. This way it always has an answer ready, even if time suddenly expires.
And then: quiescence search. This is an extension of the normal search — when a “noisy” position sits at the root of the calculation, one where pieces are being exchanged, the engine continues searching those captures until the dust settles. Without it, the engine would evaluate a position where the queen is hanging and say: “all good.”
With alpha-beta, the engine suddenly started to see things. Not much — depth 2 or 3 in normal positions. But enough to avoid hanging pieces.
That was an exciting moment. I remember playing the engine against itself. I hung a knight — it took it. My heart skipped a beat.
Opening Books
Shortly after: Polyglot opening books. These are compiled files from thousands of grandmaster games. The engine looks up whether the current position is in the book — and if so, plays one of the moves recorded there.
That might sound like cheating. It isn’t. Every engine uses this. And it makes sense: in the opening, the search tree is enormous and the evaluation function still unreliable. Why not draw on human knowledge that distills centuries of chess theory?
The books are consulted in order. Only when none of them knows a move does the engine start calculating on its own.
The result: in the opening, Martuni plays respectable chess. But beyond the opening, the gods have placed the middlegame. And there, Martuni is mercilessly on its own.
Continued in Part 2: How the engine stopped playing aimlessly.