Writing A Very Tiny Chess Program

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

  1. 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.

    1. 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.

      1. 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…

        1. “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…

          1. nope, 14

            the z80 in question was a Cromemco system with four eight inch floppy disks!

            OUT $F0,1
            EJECTED THE FIRST FLOPPY!!

            OUT $F0,0F

            EJECTED ALL OF THEM!!

            How cool is that????

  2. … 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.

  3. 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.

  4. 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.

  5. 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… :) )

  6. 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 “

    1. 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.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.