Since it's the 30th anniversary of the ZX81 computer, I thought I'd write about what I think is one of the most amazing pieces of programming ever: 1K ZX Chess.
In 1983, David Horne wrote a program that would play a game of chess that ran on the Sinclair ZX81 computer using just 1K of memory. As one of the smallest versions of the game to have a visual display of the board, it stands as a remarkable achievement. If sculpture can be described as starting with a block and whittling away anything that doesn't "feel" like the thing you're trying to create, then David has done something similar to the ZX81's tiny memory. It's hard to believe that there's a single byte left in the program that doesn't have some element of “chessness” to it.
Of course, to fit the greatest game ever into such a small space necessitated certain limitations. The program always plays as white and only makes one of two opening moves, depending which side of the cassette was used to load the game... king's pawn to king's pawn three (van't Kruijs' Opening), or queen's pawn to queen's pawn three (Miese's Opening).
The artificial intelligence of 1K ZX Chess could only look one move in advance, and the program had no concept of the newer rules of the game (ie, after the sixteenth century) such as castling, en passant, and promotion of pawns. Nevertheless, within these 672 bytes of code lie the barest bones of chess, as if this is the absolute zero of chess and below this it cannot exist in any recognisable form.
Playing the game isn't that satisfying, as it has a fondness for moving the rook back and forth between a1 and a2. If you want to break this cycle then you have to attack the square a2, and only then does it turn its attention to other things. So it's possible for it to play a good game, but only if the human opponent acts as a kind of sheepdog, guiding it towards the right move. Or at least away from a really wrong one.
If it takes one monkey seventy thousand years to type “TOBEORNOTTOBE”, then how long before 1K ZX Chess accidentally plays like a grandmaster? Having no memory of the previous game to learn from, it would be a fleeting success, never to be seen again but is there at least the potential for this game to mimic the style of every master who ever studied the game? I hope so. In one game, it suddenly pushed its queen into the fray in what seemed like a very bold and romantic move. It didn't last, though, but for a moment I felt like Prof Higgins in My Fair Lady, and I wanted to call out “By George, I think it's got it!”
(Oh, and here's a blog post in which 1K ZX Chess goes up against a newcomer to the 1K chess world, Tiny Chess.)