QUIRKAFLEEG

> WE MUST PERFORM A QUIRKAFLEEG

A new chess engine for the 48K ZX Spectrum, hand-written in Z80 assembler — and quite possibly the strongest chess program the machine has ever run.

62% VS COLOSSUS 4 ≈2100 RELATIVE ELO 100% Z80 RELEASE V2.2

Runs in your browser on an emulated Spectrum — or download it for real hardware, or challenge it on Lichess.

Type e2e4 ENTER to move · S ENTER to play Black · H ENTER for a hint · SPACE to make it move now. Full guide

ALSO ON LICHESS

Challenge Quirkafleeg-ZX48K — v2.2 as a Lichess bot. Any time control, rated or casual: log in, open the bot's profile and press Challenge. Between human games it plays rapid against other bots.

It runs the UCI build: the C reference model on a virtual 3.5 MHz clock, so your clock is its Spectrum time and it replies almost instantly. Close to the real 48K, not identical — with increment it gets a little more thinking time late in a game than the real machine would. Its Lichess rating is measured against the bot pool and is not comparable with the figures below.

PROBABLY THE STRONGEST ON THE 48K

Colossus Chess 4 has been the program to beat on the Spectrum since 1986. So that is the test.

62%
Quirkafleeg v2.2 against Colossus 4 over 200 games
+109 =30 −61 · about +85 Elo (95% interval +41 to +132) · likelihood of superiority 99.99%

Original Z80 code for both programs at real Spectrum speed · 10 s per move on average · both pondering · 100 openings, each with both colours · 145 games adjudicated by Stockfish · no crashes.

About 2,100 on a relative scale

Against Stockfish capped at UCI_Elo 2100, v2.2 scores 50.6% over 1,000 games (2,085–2,123), measured with the cycle-accurate C model of the engine. A relative figure, not a FIDE or CCRL rating.

Two schools of search

Colossus 4 searches every move full width to its horizon, then follows the captures. Quirkafleeg is selective: null-move pruning, late move reductions and futility pruning cut away moves that are unlikely to matter, so it examines far fewer positions for each ply of depth.

BUILT BY HAND, ONE T-STATE AT A TIME

More than 7,300 lines of hand-written Z80 assembler. About 130 positions per second, typically four plies in ten seconds. At that budget, almost every idea from modern engines costs more than it gains.

AT DEPTH FOUR, DEPTH IS EVERYTHING.

So nothing went in on faith. Every idea was tried in a C model that charges each operation its real Z80 cycle cost, then played over 1,000–1,500 games. Most failed — mobility, extra pawn and king knowledge, history pruning, more tuning data. What survived: tuned evaluation weights (+35 Elo), pondering, an endgame mop-up and a careful stack guard. The final build fills the 48K almost to the last byte.

7,300+lines of hand-written Z80
~130positions per second
~4plies in ten seconds
40 KBengine, tables, book and UI
4 KBtransposition table
UNDER THE HOOD

SEARCH

Principal variation search with null-move pruning, late move reductions and pruning, and (reverse) futility pruning. Check extensions, and a quiescence search that uses static exchange evaluation to skip losing captures.

MOVE ORDERING

Hash move first, then captures by most-valuable-victim / least-valuable-attacker, two killer moves and a history heuristic — so the pruning cuts in the right places.

EVALUATION

Tapered middlegame/endgame evaluation with tuned weights: piece-square tables, pawn structure, passed pawns, king pawn shield, bishop pair and rooks on open files, kept fast by a pawn hash.

MEMORY

Zobrist hashing, a 512-entry transposition table and a pawn hash. Board, attack tables, undo stack, book and screen code share every byte of the 40 KB above BASIC.

CLOCK & BOOK

Tournament time controls from 40 moves in 2 hours down to 5 seconds per move, a 347-position opening book, and pondering on your time.

VERIFIED

The Z80 code is checked bit-exact against the C model with perft checksums before anything is tuned.

HOW TO PLAY

Type a move as from- and to-square, e.g. e2e4, then ENTER. 0 deletes a character, an illegal move shows ILLEGAL, and SPACE makes the engine move at once.

Castling is the king move (e1g1). Promotion is to a queen; add n, r or b for another piece (e7e8n).

COMMANDS

Each command is one letter followed by ENTER.

NNew game (keeps the time control)
B / ROne move back / forward — always lands on your turn
SSwap sides: the engine takes the side to move and the board flips. Press at the start to play Black
TNext time control: 40/2H → 40/1H → G/60 → G/10 → G/5 → AVG5S → AVG10 → AVG30 → AVG60 → AVG3M → INFIN. AVG = average seconds per move; INFIN thinks until you press SPACE. Clocks restart. Default 40/2H
ESet up a position (below)
HHint — the move the engine expects you to play
MTwo players: engine off (M again to switch it back on)
CStop / start the clocks
FFlip the board
PPondering on/off (default on; not shown on screen)
SETTING UP A POSITION

After E: e4wn puts a white knight on e4 (pieces p n b r q k, colour w/b). e4 empties e4, c clears the board, i sets up the initial position. Finish with w or b for the side to move. The position is checked — one king each, no pawns on the 1st or 8th rank, the side not to move not in check — otherwise ILLEGAL POSITION. Castling rights follow from kings and rooks on their home squares.

GAME ENDINGS

CHECKMATE · STALEMATE · REPETITION (threefold) · 50 MOVES · NO MATERIAL · MOVE LIMIT (250 half-moves) · TIME

DOWNLOAD

QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG QUIRKAFLEEG WE MUST PERFORM A QUIRKAFLEEG WE MUST PERFORM A QUIRKAFLEEG 100% Z80 MACHINE CODE 48K ZX SPECTRUM ANDERS STRANGE 2026 CHESS
Remember the inlay? It came with the tape.

Play v2.2 on a real 48K or in any emulator.

Freeware. Free to download, play and share unmodified, including on archive sites. Not for sale.

Bonus for PC chess GUIs: the C model packaged as a UCI engine for Windows. It thinks in Spectrum time — 48K strength, instant moves. Download (zip, 99 KB) MD5 3a25ad2792077fcc35dfb2602265a31b

COMING NEXT

IN DEVELOPMENT

Quirkafleeg for the ZX Spectrum Next: more memory, a Z80 at up to 28 MHz, deeper search, a much larger opening book and a new interface. No release date yet.

Try it early: an experimental build of the Next engine plays on Lichess as Quirkafleeg-ZXNext — the C model on a virtual 28 MHz Next clock, with the Perfect 2023 opening book by Sedat Canbaz. Challenge it at blitz or rapid (5 minutes or more). A work in progress: expect it to change.

WITH RESPECT TO MARTIN BRYANT

Anyone writing chess for the Spectrum stands on Martin Bryant's shoulders. Colossus Chess 4 (CDS, 1986), grown out of his White Knight Mk 11 — winner of the 1983 European Microcomputer Chess Championship — has been the program to beat for forty years, and one of Quirkafleeg's evaluation terms borrows an idea from it. That a modern engine still has to fight for every point says everything about how good Colossus was. Thank you, Martin.

WHY "QUIRKAFLEEG"?

THE Z80 MUST PERFORM!

The name is a room in Jet Set Willy (Matthew Smith, 1984): “We must perform a Quirkafleeg”. The game never says what a Quirkafleeg is. Here it is a dance — and after all that hand-written machine code, the little Z80 has earned the right to perform it.