QUIRKAFLEEG
> FOR THE COMMODORE 64 AND 128
A new chess program for the Commodore 64, written in 6502 assembler — and the strongest chess the C64 has ever played on its own processor. On a C128 it runs faster still.
Runs in your browser on an emulated C64 at its real speed — or download it for real hardware and emulators.
Type e2e4 RETURN to move · F1 to let the computer play the side to move (press it first to play Black) · ? for a hint · F5 for the level. Your keyboard works too (Shift+F1 = F2). Full guide
THE STRONGEST CHESS ON THE C64 AND C128
Colossus Chess 4.0 by Martin Bryant (1985) has been the strongest chess program for the Commodore 64 for forty years. So that is the test.
131.5 points: +121 =21 −58 · about +113 Elo (95% interval +67 to +163)
Both programs as original 6510 machine code on an emulated PAL C64 at real speed · Colossus at its standard level (12.6 s per move on average), Quirkafleeg 40 s + 11 s per move (10.7 s on average) · both pondering · Quirkafleeg's board on screen while it thinks, as in the program · 100 openings, each with both colours · every game played to the end, no adjudication.
And The Final ChessCard?
The Final ChessCard (TASC, 1989, programmed by Marc Derksen) is not C64 software: it is a cartridge with its own 65C02 processor at 5 MHz, its own ROM and its own RAM. The C64 runs only the screen and the menus. It is the strongest chess you could plug into a Commodore. Quirkafleeg plays it on the C64's own 1 MHz — and holds its own.
224 different games from the start position, both programs with their opening books: +109 =25 −90 · about +30 Elo (95% interval −13 to +73)
So level, perhaps slightly ahead — not proven. From 200 set, balanced openings it scores 48.4% (about −11 Elo). On a C128 in its 2 MHz mode it is clearly stronger: 70.2% over 400 games (+254 =54 −92, about +149 Elo, 95% interval +117 to +184).
The card's original ROM (v3.6) on an emulated 65C02 at 5 MHz. Quirkafleeg as the cycle-costed C model of its 6502 engine, which charges every operation its real 6502 time on the C64 (or C128) clock. 40 s + 11 s per move, no pondering on either side. Both programs repeat themselves when the openings repeat, so identical games are counted once.
A C128 makes it stronger
On a Commodore 128 (in C64 mode) Quirkafleeg finds the 2 MHz mode by itself. Against Colossus 4.0, under the same conditions as above:
| Machine | Score | Elo |
|---|---|---|
| C64 | 65.8% (+121 =21 −58) | +113 |
| C128, 1.4× (default: 2 MHz in the border, board visible) | 68.0% (+121 =30 −49) | +131 |
| C128, 2 MHz (screen off while thinking) | 81.4% (+152 =20 −27) | +257 |
The 2 MHz row is an upper bound: in that test both programs also pondered at 2 MHz. One game of the 200 ended in a test-rig error and is left out.
6502, ONE CYCLE AT A TIME
Quirkafleeg began on the 48K ZX Spectrum, where it beat Colossus Chess 4 too. The C64 version is not a translation: the engine was rebuilt in 6502 assembler and then measured, cycle by cycle, against what the 6510 and the C64's 64 KB actually allow — fixed piece slots, the opening book hidden in the RAM under the I/O chips, the board kept on screen while it thinks.
AT 1 MHZ, EVERY CYCLE IS A DECISION.
Every change was played over hundreds of games before it stayed in. Most did not. The program takes over the whole machine on its first instruction: BASIC and the KERNAL are switched off, and the 64 KB are shared between the engine, its tables, the book, the screen and the interface — to within a few bytes.
UNDER THE HOOD
SEARCH
Principal variation search with null-move pruning, late move reductions and 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, killer moves and a history heuristic.
EVALUATION
Tapered middlegame/endgame evaluation with tuned weights: piece-square tables, pawn structure, passed pawns, king pawn shield, bishop pair, rooks on open files and an endgame mop-up, kept fast by a pawn hash.
MEMORY
Zobrist hashing, a 512-entry transposition table, a pawn hash and a 4 KB opening book in the RAM under the I/O chips. The screen and character set live in the top 16 KB bank.
CLOCK & PONDERING
Eight levels from 5 seconds per move to 40 moves in 2 hours, clocks for both sides, and pondering: it thinks on your time and answers at once when you play the move it expected.
C128
Detects a C128 in C64 mode and uses its 2 MHz mode: 1.4× with the board visible (default), 1 MHz, or a full 2 MHz with the screen off while it thinks. F4 switches.
HOW TO PLAY
You play White. Type the move as from- and to-square, then RETURN: e2e4 RETURN. Typing a square with one of your pieces selects it, so e2 RETURN e4 RETURN works as well, and typing another of your pieces changes your mind. Letters and digits move the cursor; the cursor keys and a joystick in port 2 work too (RETURN or fire selects the piece under the cursor, then the square to move to). An illegal move is simply not played.
Castling is the king move (e1g1). When a pawn promotes the program asks Q R B N ? — press the letter (RETURN = queen).
While the computer thinks, the two lines under the status bar follow its search: after each finished depth, the score so far and the best move so far, e.g. White +0.35 / Depth 5 Nf3, in white. After each of its moves the same lines show how the computer sees the position, in pawns — Equal, White +0.65, Black +1.20 or White mates — and the reply it expects from you, e.g. Expects Bb5. Moves are shown in standard algebraic notation (Nf3, exd5, O-O, e8=Q, Qxf7+).
KEYS
| F1 | The computer plays the side to move — press it at the start to play Black, or to switch sides |
| F2 | Opening book on / off (Shift+F1) |
| F3 | Turn the board |
| F4 | C128 only: speed 1.4× → 1 MHz → 2 MHz (Shift+F3) |
| F5 | Level, before the first move: 5, 15 or 60 s per move, 5 min game, 15 min + 10 s, 60 min game, 40 moves in 2 hours, depth 4. Default 15 s per move (an average; a single move can take up to twice that) |
| F7 | New game |
| ? | Hint: the move the computer expects from you; RETURN plays it |
| − / + | One move back / forward. After going back the computer waits: play on yourself, or press F1 |
| s | Set up a position (below) |
SETTING UP A POSITION
After s: move the cursor with the cursor keys, the joystick or the digits. p n b r q k put a white piece, the same key again makes it black; x or DEL empties the square, c clears the board, + changes the side to move, RETURN starts. Use the cursor keys for the b- and c-files (in set-up mode b is a bishop and c clears the board). The position is checked: one king each, no pawns on the 1st or 8th rank, the side not to move not in check. Afterwards the computer waits for F1, so you can also enter moves for both sides.
GAME ENDINGS
CHECKMATE · STALEMATE · TIME OUT · DRAW BY REPETITION (threefold) · DRAW BY THE 50-MOVE RULE · DRAW BY MATERIAL (no pawns, rooks or queens and at most one minor piece) · a game that reaches 255 half-moves is drawn too (shown as Draw: 50 mv.)
DOWNLOAD
Beta 4 for a real C64 or C128, or any emulator (VICE, CCS64, an Ultimate 64, a THEC64). One file, no copy protection.
LOAD"QUIRKAFLEEG",8 then RUN
174,848 bytes · MD5 65894c265e65c14a68a0018d6d9ce71b
.PRG
The program alone — drag it onto VICE, or put it on an SD2IEC.
47,105 bytes · MD5 78e53718655eab69455c9ad85575065d
From a standard 1541 the load takes about two minutes; any fast loader (JiffyDOS, Action Replay, Epyx FastLoad, an SD2IEC with a fast loader) cuts it to seconds. README
Freeware. Free to download, play and share unmodified, including on archive sites. Not for sale.
THIS IS A BETA
New in beta 4: the computer shows its thinking as it goes — the score and best move so far after each finished search depth. Fixed: when one of two pieces that could reach the same square was pinned, the move list wrote e.g. Ngf6 instead of Nf6. Beta 3: moves in standard notation (Nf3, exd5, O-O, Qxf7#) in the move list, the hint and the expected reply, and a plain assessment line (Equal / White +0.65 / Black mates). Fixed: in a rare position whose book key matched another position, an illegal “book” move could be played. Beta 2: type a move in one go, e2e4 RETURN; and when you play the move the computer expected, the board now shows the right position while it answers (beta 1 could show an older one until the reply).
Before beta 1 Quirkafleeg played 179 complete games against Stockfish in an emulated C64, every move typed on the keyboard and every move and game end checked by a separate program; beta 2 another 40, half of them typed the new way; beta 3 another 80, every move in the list checked against a reference implementation of the notation; beta 4 another 40, with the live lines checked as well. It has been tested in emulators — our own and VICE — but not yet on real hardware, and the C128 modes only in our own emulator. That is where you come in.
Known limitations: a repetition created by your own move is noticed one move later; with a single legal move the computer still thinks for its normal time; keys typed in the first tenth of a second after the computer's move appears can be missed. Planned for later: a help screen.
If something goes wrong, please note the level, the moves (or a photo of the screen) and what happened.
ALSO ON THE ZX SPECTRUM
Quirkafleeg started on the 48K ZX Spectrum: 62% against Colossus Chess 4 over 200 games, about 2,100 on a relative Stockfish scale. Play the Spectrum version in your browser, or challenge it on Lichess as Quirkafleeg-ZX48K.
WITH RESPECT
To Martin Bryant, whose Colossus Chess 4.0 set the standard on the C64 in 1985 and held it for forty years — and to Marc Derksen and TASC, whose Final ChessCard showed in 1989 how much chess a 6502 could play when it was given five times the speed. Matching them took a modern engine and every cycle the C64 has.