The Kilobyte’s Gambit is a delightful, painful reminder
How chess played in just 1K of code is putting Gigabytes and Gigahertz to shame
KOSTAS FARKONAS
PublishED: March 19, 2021
Sometimes it takes a virtual kick in the head to be reminded that certain things have gone astray in the tech world. One of them: clean code. Most smartphone or laptop owners – used to GB of system memory and TB of storage – probably won’t believe this, but some of us remember using computers with 16K of RAM (hello there Sinclair ZX Spectrum). That is 16K, not 16MB (which is a thousand times more): an amount of memory so small, so insignificant as to defy comprehension. The favicons of websites on our browser toolbars take up around 4K or more. So nobody would possibly be able to do anything with 1K of RAM today, right?
Wrong.
Anyone old enough to remember the Atari ST/Amiga days surely remembers the demo/intro scene, where expert programmers tried to cram as many dazzling graphics routines playing in a loop in as little an amount of memory as possible. There have been several true audiovisual works of art created by talented programmers like that, weighing in at 16K or less. Well, modern hackers have their own version of that competitive demo scene, called “the 1KB challenge”, where they try to make something fully functional and usable taking up no more than 1K of memory. Some of them did manage to produce amazing results in recent years by utilizing assembly (direct “to the metal” coding) and advanced programming techniques.
But even knowing all that does not prepare most people for The Kilobyte’s Gambit. It’s a Web game hosted by Vole.wtf — a site known for its GeoCities aesthetic and the wonderfully weird stuff collected in its pages — that does the impossible: it offers a fully functional, fully playable chess simulator depending on 1KB of JavaScript code.
The “engine” itself (the instruction set needed to dictate how a chess game is played) is based on the work of programmer Oscar Toledo G and his 1K Chess experiment. The source code of that engine is less than seventy lines long and can be compiled by various modern programming languages, but JavaScript was chosen in order to make the game playable inside any Web browser in almost any computing device.
Since Netflix’s The Queen’s Gambit show made chess wildly popular late last year, The Kilobyte’s Gambit goes for that Beth Harmon famous pose and some lovely 8-bit quality graphics. It works. But the very fact that one can play chess — one of the most complex board games in human history — with a computer that’s using just 1KB of memory to decide its moves is nothing less of astounding. The AI is no Deep Blue, of course, as it would need a library of moves and games of multiple GB in size in order to present seasoned chess players with a serious challenge, but still: 1KB of RAM. The mind boggles at the simple thought of it.
It all goes to show that since the late 80s, somewhere down the line, clean code just stopped being a priority for software companies. The code they produced for operating systems, applications, games, you name it became less and less lean and efficient, more and more bloated and resource-demanding, to the point where (voila!) hardware upgrades were needed to run all those productively. We are now at a point where devices that fit in our pockets possess enough processing power to send rockets to space, but they often do not feel powerful enough for everyday tasks.
This can’t be easily undone now, as it would surely require a complete reset of all systems, protocols and platforms all modern apps and services depend on. But developers of all levels could make an effort to return to the clean code ethos whenever possible. Maybe what cannot be done in one broad sweep, could be achieved little by little over time. Maybe.