I've been a keen chess player since I bought a Spears' Games plastic set in the early 1980's. (I still have it!) But the world of computer chess has always been beyond my abilities. After all, so many better chess players than I have written engines that even I can beat. So what chance would I have?


So I took a different approach - what if you could play ZX 1K chess for the ZX81... without a ZX81!?!?

For this I took a JavaScript emulator running the original game, and re-wrote parts of the original Z80 assembler code, so that I could inject the current game state, and parse out the new game state. It was time-consuming, but not something the average Jo gets to work on!

Then, I hooked this code into the API provided by lichess so that it could become an online chess bot, and play against humans. (And potentially other computer chess programs.)

Of course, the ZX-Chess bot has all the original limitations (such as the lack of en passant, castling, and promitions) and the original bugs. But it's an amusing proof of concept if nothing else!

How to play

Technical details

There's far to many to go into here. If enough emails me wanting to know (i.e. if anyone emails me!) then I'll write up the process.

Essentially it's:

  • Chess the emulator working
  • Debug the code to determine memory locations for the board, player input, AI, and changing the move (the latter is surprisingly crucial!)
  • Add breakpoints to the emulator, to inject a new game board
  • Parse FEN (chess notation) into a ZX81 data stream, and hot-wire the memory
  • Re-write the assembler to ignore player input, and make an AI move
  • Determine when the AI had finished. Note that the screen update isn't synchronised with the memory update.
  • Extract the board data into a JS array
  • Compare the game state with the original state and determine the move made
  • Present this move in algebraic notation
  • Write all the lichess APi stuff
  • Package the JavaScript code into Node, stubbing out DOM routines, and inlining binary data

See also

I also convert the Lozza chess engine to work under lichess.org - it was much easier!


ZX-Chess, the bot profile
About the original 1K Chess
Subvert Ltd, owners of the IP

Lozza bot, my first non-trivial bot
The original lozza code
My lichess bot engine, and re-vamped lozza code