The world's smallest chess engines

by Albert Silver
9/23/2015 – In the world of chess computing, the actual records that are sought after usually deal with the chess engine 'arms race' for the highest Elo. After all, it is the easiest thing to measure. However, until recently there was another record that had stood the test of time for decades: the world's smallest chess engine. The new champions are as small as three Twitter messages.

ChessBase 14 Download ChessBase 14 Download

Everyone uses ChessBase, from the World Champion to the amateur next door. Start your personal success story with ChessBase 14 and enjoy your chess even more!


Along with the ChessBase 14 program you can access the Live Database of 8 million games, and receive three months of free ChesssBase Account Premium membership and all of our online apps! Have a look today!

More...

The smallest of them all

The first thing to do is understand what the smallest chess program means. We are not talking about fitting it into something the size of the eye of a needle. We are talking about the smallest amount of actual code required to build a fully-functional chess program that can be played against.

The previous champion was a chess engine that was built almost out of sheer necessity: 1K ZX Chess - a Sinclair ZX81 computer game, which contained 672 bytes of code. They say that necessity is the mother of invention, and this little programming gem fits the bill in the spades.

The Sinclair ZX81 was a pioneering computer that came out in 1981, designed to make it possible to put personal computers in the normal blue-collar homes of the time. To understand the market then, the kings of the heap such as the Apple II retailed for well over US$1000, whereas by contrast the ZX81 cost an incredible £49.95 for the kit, which even today translates to roughly £171 in 2015. This feat wasn't done by using sweat factories in China, but by its brilliant Spartan design, albeit fully functional.

The legendary Sinclair ZX81. Today's Raspberry Pi is a tribute to its minimalism and affordability.

The ZX81 was designed to be small, simple, and above all cheap, using as few components as possible to keep the cost down. Video output was to a television set rather than a dedicated monitor. Programs and data were loaded and saved onto audio tape cassettes. It had only four silicon chips on board and a mere one kilobyte of memory. The machine had no power switch or any moving parts, and used a pressure-sensitive membrane keyboard for manual input. The operating system was Sinclair BASIC.

It was hugely successful, selling more than 1.5 million units, however its limitations required the utmost creativity in software design. You may have noted the one kilobyte of RAM, and thought it was some form of typo. It was not. It literally had one kilobyte, which is one millionth of 1GB.

The original cover of the 1K ZX 81 chess program

The British programmer David Horne managed to create a chess program that fit within those draconian restrictions and in a mere 672 bytes had a working chess program. Understandably, as such restrictions were lifted with the ever-evolving computers, the subsequent focus was more on trying to exploit these newer technologies, and see how far they could go.

It was a different time, and in the February 1983 issue of 'Your Computer' a detailed article
with the complete code was published by the author himself. Here is the cleaned up code.

 

This is what a game against 1K ZX81 Chess looked like

Today it is clear that these limits, which at first existed due to floppy disc space, then CDs, then DVDs, no longer exist really. Massive virtual reality quality games that take up dozens of gigabytes of space continue to come out and grow. Coming around to full circle, there is now a movement called 'sizecoding' that challenges programmers to seek to be as efficient as possible in their coding, optimizing not only for speed but sheer code size.

To this day, 34 years later, there are still active forums on the machine and programming it

This is how BootChess eventually came into existence. The French coder Olivier Poudade managed to produce a chess engine in code that can be run on Windows, MacOS and Linux, in just 487 bytes! To grasp how absurdly small that is, just over three imageless Tweets would take up about that much data.

Although some have criticized BootChess for not being able to handle the rule of castling, it must be noted that nor could 1k ZX Chess. On the other hand, 1K ZX chess was also unable to handle pawn promotion into a queen, whereas BootChess can.

This is a screenshot of the BootChess page where the code can be freely studied and copied to try out.
You will note the detailed notes on the right side of the actual code to help understand how it works.

To achieve his goal, Mr Poudade - a member of the Red Sector Inc coding group - had to make the look of his game even more basic than its 1982 predecessor. The board and pieces of BootChess are represented by text alone, with P representing pawns, Q used for the queens and full stops put in the place of empty squares.

Full functionality

The caveats of the claims have been made, and while BootChess is certainly smaller and more functional than its great predecessor, it is nonetheless unable to play according to all the rules, such as en-passant or castling. This is understandable. Mark Lefler, the programmer of Komodo 9, explained, "castling and en-passant take up a lot of code to get right."

So who are the true kings of fully functional minimalism? Only two programs under 2kb today are able to play a game with all the rules, no shortcuts allowed: Tiny Chess and MicroMax.

Toledo Nanochess is a miniature chess program that was written in JavaScript by Mexican developer Oscar Toledo G, and that fits in just 1251 bytes and is available to play against with a proper graphical representation of the board and pieces. Try your hand against it at Tiny Chess.

MicroMax is the strongest of the minatures and will actually give
you a decent game without being a bully. Well worth a try!

MicroMax is programmed by Dutch programmer H.G. Muller, who is also the author of the graphical interface Winboard. MicroMax is exactly 1433 characters long, and can be downloaded at the author's official page. He also provides generous commentary on the challenges and its inner workings. You can also find information at the ChessProgramming Wiki page.



Born in the US, he grew up in Paris, France, where he completed his Baccalaureat, and after college moved to Rio de Janeiro, Brazil. He had a peak rating of 2240 FIDE, and was a key designer of Chess Assistant 6. In 2010 he joined the ChessBase family as an editor and writer at ChessBase News. He is also a passionate photographer with work appearing in numerous publications.
Discussion and Feedback Join the public discussion or submit your feedback to the editors


Discuss

Rules for reader comments

 
 

Not registered yet? Register

mbehna mbehna 9/27/2015 06:56
Wow! talk about coding efficiency. But that's why assembler will always be used for such things.
Bertman Bertman 9/24/2015 06:51
@PWCCA

Of the mini engines, Micro-Max is the hands-down strongest. This is not to suggest it plays like a master, but just that it beats the others.
jeroen jeroen 9/24/2015 12:22
"pressure-sensitive membrane keyboard", today they call it 3d Touch
pwcca pwcca 9/24/2015 11:02
Tiny Chess does not understand stalemate. It just passes its move.

What about rating vs size ?
1