LeanChess - the smallest computer chess in the world

My name is Dmitry Shekhtman, and I am the author of the smallest computer chess in the world.







It all started with the fact that my (now former) girlfriend suggested writing computer chess. The idea interested me, and I decided to do it. True, after reading the Internet, I realized that I was forty years late. Oscar Toledoโ€™s chess developments were particularly impressive - in C 1257 bytes, JavaScript in 1023 bytes, and finally Atomchess in x86 assembler, compiling in 392 bytes.







Before I returned to the topic, several months passed. As it turned out, a new size record was set during this time - ChesSkelet for the ZX Spectrum took only 352 bytes. True, he did not know all the rules and played very weakly, but still! But do I swear at the assembler chess? I thought.







It was decided to write under 8086. It should be noted that the task of optimizing the size of machine code was not originally set. The chances of surpassing Atomchess seemed to be tending to zero, not to mention competing with the world champion - an assembler implementation of an eight-bit processor.







A few days later I had in my hands a program that displayed a board with pieces (in the form of eight lines of text) and a move generator that supported castling, replacing pawns with arbitrary pieces and taking in the aisle. True, with a slight caveat: the program did not work.







As a result of several "restarts" with the exception of all the superfluous, a rather elegant code was obtained. Anticipating the objection that a pawn jump through the field cannot be considered superfluous, I suggest that you familiarize yourself with the description of the possibilities of ChesSkelet-352. At some point, the idea arose of switching to optimization. As it turned out, with a decrease in the size of the program, it becomes more accessible for understanding and debugging. Adding comments to each line helped a lot. In the end, a mistake was found.







When it seemed that there was nowhere to optimize further, the pusha and popa commands were discovered quite by accident, which allowed saving about 18 more bytes (the exact data was not saved). Atomchess was defeated. True, due to increased system requirements - to IBM PC AT.







Without stopping at the further stages of development, we will pass to the results. The minimum variation in the form of a COM file for DOS is 328 bytes - 24 bytes less than the previous record holder (recall, eight-bit). As already mentioned, we are not talking about full-fledged chess. The opponentโ€™s moves are not checked for correctness at all. But the AI โ€‹โ€‹is implemented in the form of a full NegaMax search of three half-pass depths with an estimate of the material (with an increase in depth to four, the speed is acceptable).







LeanChess is currently available in the following variations:







  1. Barebone DOS (328 bytes)
  2. Barebone BIOS (333 bytes)
  3. Classic DOS (338 bytes)
  4. Classic BIOS (342 bytes)


All four (now) play the same way, the differences are only in the display of the board (and keystrokes). Do not be surprised at the "officers" in the form of O in variations of Barebone.







In order to run the game, you will need a DOSBox. Enter moves in e2e4 format without pressing Enter. After losing, close the emulator window.







Screenshot



image

References





PS If you are interested in technical details, please let us know in the comments.

PPS Version 1.1 has been published with the correction of the elephant rating and the addition of the Classic DOS Edition.








All Articles