When programming for modern platforms, the restraints are different to those of 30 years ago. Back in the dawn of the microcomputer age, storage and RAM were measured in kilobytes. It simply wasn’t possible to store large amounts of graphical data, and even code had to be pared back at times. [reeabgo] found out some of these limitations first hand, when coding a tiny chess program for the Sinclair ZX81.
[reeabgo]’s project goes by the name ChesSkelet, and is truly tiny. Measuring in at just 377 bytes in its smallest version, the entire program takes up less space than this very article describing it. To achieve these feat requires certain sacrifices, of course. The tiniest edition contains no graphics whatsoever, representing the game state with simple characters and featuring no adornments whatsoever. The full-fat version comes in at 477 bytes and adds quite a lot of functionality. There’s a proper checkerboard, along with move legality checks and pawn promotion.
Unfortunately, advanced chess play isn’t quite possible – castling is not implemented, and the AI doesn’t yet handle check situations properly. Despite this, it’s a solid approximation of the real game, all packed into an impressively small space.
We see plenty of chess hacks around these parts – including the robotic variety.
29 thoughts on “Writing A Very Tiny Chess Program”
Maybe it’s a naive thought, but when I read about how much was accomplished on the limited hardware of the past, I start to think maybe our modern programming mindset could use a little work.
I live in fear of just how bad the “OS” on the Enterprise is!
A VM, running under emulation, running on Q code, running on a VM
Nah, Lcars runs on 640K of memory since that’s all anyone *really* ever needs.
There will always be a tradeoff between abstracting away how the hardware works and coming closer to being able to “code how you think”, instead of having to “think how you code”.
I think there is beauty and productivity to be found in both of these schools of thought. A well laid out C# program just flows through your mental cortex, while a 30 line assembler program might take a while to understand, but can be so optimized to solve a certain problem that it puts you in a religious mental state once you understand it.
back then with a 4gl the worst thing that could happen was
“stack collision with heap”
I was spoilt with the 14 addressing modes of the 6502, records were easy
going to a z80 was like trying to type with oven mits on…
“going to a Z80 was like typing with oven mitts on”
But that’s mostly because of the rubber key spectrum, right?
Because it had a whole TEN addressing modes.
And I thought the 6502 has 13 addressing modes not 14…
the z80 in question was a Cromemco system with four eight inch floppy disks!
EJECTED THE FIRST FLOPPY!!
EJECTED ALL OF THEM!!
How cool is that????
OUT $F0,$0F sounds like you’re trolling me
But it sounds cool anyway F00F!
And I’m pretty sure it’s 13, I wonder what the missing one is?
Going from Z80 to 6502 was just as hard.
Who could forget the LDIR insttuction.
Abstract approaches CAN actually speed up things, because your problem approach might be entirely different.
Make programmers write all their code on a ZX81 first, that will concentrate their minds.
There was an attempt a while ago to do it in 256 bytes. It wasn’t broadly accepted (by the scene), nevertheless it’s noteworthy : http://www.pouet.net/prod.php?which=67226
Probably worth linking to the original ZX81 1K Chess:
… a confusion in the post about whether the program is for the ZX Spectrum or the ZX81. The image up there shows a ZX81, which also is mentioned in the body of the post. But the screenshot is from a ZX Spectrum, and that’s also what the linked page says.
While this is impressive, 1k zx chess only takes up 672 bytes and includes, a checkerboard, castling, and a computer opponent and it was written in 1982. This is still very impressive though.
This was my first computer, the one I learned to code with.
I still have it.
One of the early wonders of the micro-age was Peter Jennings Microchess that fit into an unmodified KIM-1 with a whopping 1.1K of memory. Same sort of limitations: no castling an no en passant. Like always with these things, though, the miracle is not how well the bear sings but that the bear sings at all.
Here’s a Really Small chess program:
If Black: resign immediately
If White: e2-e4 then resign
Never said it was a GOOD chess program…
Anyone recall the 1K ZX81 flight simulator? – I just had a quick look and can’t find much about it. (ISTR it was more or less just an artificial horizon which responded in a simple way to keyboard coontrols… i.e. a line-drawing algo whos start and end points sort of behaved like a(n) horizon, if you used your imagination and squinted a bit… :) )
Found the online emulator with it…
Yes, the 16Kb one. I wondered about the 1Kb one… and code behind it would be nice
Here’s the 6502 source to microches.
The ZX81, did it have the first FPS (sort of)??? Remember T-Rex? :D
I don’t get it….? The link within the article goes to a page all about a tiny chess program for the ZX Spectrum, not the ZX81.
Doesn’t anyone check these links, pages, and article material?
“ChesSkelet is a micro chess game for ZX Spectrum, maybe the smallest ever. I first thought of ChesSkelet after reading about David Horne’s ZX81 1K Chess from 1982 “
I suspect that it is done on a Spectrum to make it less tedious. I suspect even the 1k ZX81 Chess was developed with a RAM pack.
If you read the original articles on the ZX81 chess you had to set variables by hand, then delete lines of the program itself, just to make enough room in memory to run the code.
Chesskelet was down for some time. You can find Chesskelet online again at https://chesskelet.com
Please be kind and respectful to help make the comments section excellent. (Comment Policy)