Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Chess game in 487 bytes – new record (pouet.net)
177 points by jamesbrownuhh on Jan 27, 2015 | hide | past | favorite | 51 comments


I keep saying it, but the demoscene is probably the 3rd great software movement (after commercial software and open source/free).

It's a weird kind of 3rd way, it's not open source, it's free as in beer, there's tons of help/guides/talks available, but source is rarely made available due to the competitive nature of the scene. Demogroups (or members of groups) frequently end up in the commercial world and it's been C64->Amiga->DOS->Windows for the most part, almost completely skipping Linux, OS X and other x-nix derived platforms (though there are plenty of exceptions). It's unusually prolific, there are literally tens of thousand of pieces of software and at least a half million pieces of music produced by the scene...and it's almost entirely purposeless with scant few connections to the commercial world.

The result is frequently stunning technology and art (and sometimes technology that's so elegant it's basically art on its own), splinter scenes and a constant showcase of real-time techniques that continue to push what even grizzled computing veterans think is possible.

And oh yeah, it's mostly populated by people young enough to have not even graduated college.


It's not chess if it doesn't allow castle. From the comments (http://www.pouet.net/prod.php?which=64962#c715279):

> Well... It is clear to me that you put more interest in making a small chess program that in making a good chess program. That's understandable even if the result is a program very easy to beat but... you cannot say that BootChess is a complete chess program because it does not allow to castle (didn't tried promotions, underpromotions, en passant pawn captures, stalemate... but I bet that are not supported, are they?) and, worst, it does not care about avoid to place a King in check. Every chess player knows that it is illegal (the movement CANNOT be made) to place your king on a square controlled by your rival pieces. If you allow it, then this is not chess.


Well, the 1982 1k implementation he was trying to beat did not cover these rules either. In fact, this version implements pawn promotion to queen, which the ZX 1k version did not. So the part about beating a 33-year-old record stands.

An interesting challenge would be to see if you can add all the missing rules and still keep it under 1k. So the lovers of strict definitions would finally have their version!


Another interesting question: If you could design your own instruction set, what is the smallest you could make a complete chess program? Is there an ultimate limit, information-theory style?


I propose an instruction set which consists of a single instruction. I'll give it the mnemonic CHS, and when executed, it causes the CPU to play a game of chess with the user.

(That's a long way to say that the question is somewhat under-constrained.)


I propose yet another instruction set in which the CPU, unless interrupted, plays a game of chess with the user. 0-byte program achieved.


Come now, that's cheating!


It's not cheating if the CPU is a Chess Processing Unit. :)


That's wordplay masquerading as understanding.

Instead consider a CPU architecture and accompanying notation designed especially for playing chess. The other idea is not very interesting.

Assuming some arbitrary architecture plus the necessary code to emulate it on a normal architecture (including your stupid CHS example) would normalize the "size" of the program, anyway -- unless there are hardware structures that are especially good for chess. Which was the essence of the question.



" It is clear to me that you put more interest in making a small chess program that in making a good chess program"

That's pretty much obvious

It's an exercise in programming, it's not "the ultimate chess software"


"Chess program" has to be defined in a way the general audience can agree to. Many people could also code a non-chess implementation in much less than 487 bytes and call it chess.

It still looks like an impressive exercise, but any talk of broken records demands widely accepted set of rules that have been met.


Not when the predecessor also doesn't meet those rules.


The obvious interpretation of "good" in that sentence is that it would allow the player to play chess according to universally defined and agreed-upon rules. Castling is one such rule. While I think one could argue there is some leeway with allowing the king to move into check since it doesn't prevent 2 players familiar with the rules from playing a valid game, inability to castle does not pass this litmus test. Castling is integral to the game and is neither obscure nor rarely invoked, even at the novice level - a game without it is simply not "chess". While I agree this is an impressive programming exercise and worthy of recognition in its own right, calling it a "new record" is like claiming a marathon record after running 25 miles


To play the devil's advocate, castling was a pretty late addition to the rule of chess compared to most other rules, so there used to be a game called "chess" which did not feature castling (nor the option to move pawns initially by two squares). Some regional variants of chess https://en.wikipedia.org/wiki/Indian_chess did not feature castling fairly recently (and differed from mainstream chess only by a few points), and there are stories of Indian chess players who became masters in Europe (as late as the early 20th century) even though they had learned to play without castling (can't recall the name of the one I had in mind, but there are such anecdotes at least for Mir Sultan Khan).

I agree that it would be nicer if the implementation followed FIDE rules, though, and that not being able to castle significantly changes the strategy.


Yes, totally agree. I think we could be lenient on moves validity - let's accept that the program will work correctly only if the opponent plays legal moves, and it also doesn't need to castle. Maybe it is also not necessary that it will detect mate or stalemate, we can assume that some external arbiter will end the game. But what I think a chess program absolutely needs to implement to be called a chess program is:

- should be able to play with both white and black

- support all normal moves obviously

- must allow opponent to play any legal move (castling, en passant, promote pawn to any figure)

- must not keep its own king in check


This lack of full chess rules implementation really grates on me.

As someone said on proggit, this claim is similar to claiming to be the fastest 100m runner, except you ran 70 yards.

There should be an ongoing challenge to implement a full chess rule spec in as small a program as possible.

FIDE rulebook(warts and all) is one place to start: http://www.fide.com/component/handbook/?id=124&view=article


What about moves validity, and detection of mate/stalemate? Would it be ok that the program assumes, that the opponent is playing legal moves only? Also, should it be required to detect mate and stalemate, and stop playing at that point?

Also, there is a 50-moves rule and 3rd position repetition rule, but I believe this doesn't need to be implemented, since you are not required to invoke the rule.


You are correct, the program does not follow all the rules of Chess, but I think we can celebrate a small technical achievement without getting too bogged down in defining what exactly a Chess program is.


I'm glad they mentioned 1K chess for the ZX81 [1] which I remember typing in from a magazine listing, and then playing against quite a lot (it was better than a 10 year old me). Neither program is capable of castling.

[1] http://users.ox.ac.uk/~uzdm0006/scans/1kchess/


If they can't castle then they aren't complete.

Or do you mean the ai can't castle, but you can?


It was a ZX81. "It's not a complete implementation" was presumed for anything running on that tiny thing. The base model had 1K RAM, which included all video & OS memory space. Getting it to do anything meaningful was a challenge. That somebody, back then, could get a sane implementation closely approximating chess running on it was amazing.


1K Chess for the ZX81 was 672 bytes long; the ZX81 had 672 bytes free. (Although it was more complicated than that because the ZX81 'framebuffer' changed size depending on what was on the screen, so a screen that was mostly white gave you more spare RAM.)

Also, because the ZX81 more-or-less did its video in software (again, it's more complicated than that; if you really want to know, you'll need a strong stomach. Let's just say that it hinged on abusing the Z80's built in DRAM refresh and the framebuffer was executable), which meant that the only time you could do processing with the screen turned on when it wasn't doing video. And the video took 75% of the run time.

The ZX81 was less a computer and more of a pile of hacks flying in close formation. The fact it ran at all was a miracle.


How the ZX81 display file worked:

http://www.user.dccnet.com/wrigter/index_files/ZX%20Video%20...

Note the encoding of that page causes it to render incorrectly at least in Firefox. Using View → Character Encoding → Western fixes that for me.


"Hacks flying in close formation" made my day :) Thank you for that lovely phrase.


The ZX Chess AI could not castle. It wasn't possible to enter a castling move for the human player either. Also looking at the Wikipedia page I see it didn't understand "en passant" or queening either, so it plays a reduced version of chess.


I've got an even shorter program that plays a more reduced version of chess. It's 0 bytes.


Which subset?


The empty subset.

The title claims it can play chess, this is not chess.


How small can you make a program that makes pedantic, technically correct, but completely useless comments on the internet?


Depends on how you define "pedantic".


Nice answer (and username).


https://xkcd.com/810/

I think that problem requires at least as much space as the brain module that determines "usefulness", which means quite a lot of space.


In the readme file (BootChess.txt) He quotes a great HN comment thread (https://news.ycombinator.com/item?id=7940938) from (https://news.ycombinator.com/item?id=7940212), a 128 byte raycaster written by the same author. The title of that section is "Proving know-how remains valued". This post has already generated some similar gems like this one (https://news.ycombinator.com/item?id=8954853).


Nice to see this appear on HN!

For info the author also released an impressive serie of very tiny intros ranging from 64 to 256 bytes which can be found on his personal site : http://olivier.poudade.free.fr


The README file is really interesting: http://lpaste.net/119343


If you enjoyed that README, you might also like Jason Scott's talks. See this one about the history of early pirates in the BBS days:

https://www.youtube.com/watch?v=a5AceLYWE1Q


Thanks! Looks interesting. :-)


The README is 128 times larger than the program...



For interesting contrast: Toledo Nanochess http://www.nanochess.org/chess3.html is the smallest C implementation of a full & decent chess program.


Couldn't get the OS X binary to mount and I'll have to fire up a VM to try a different binary.

However there is a nice txt file, Bootchess.txt that has some interesting excerpts. I was curious if it has an AI, to which it does:

" Usually the heart of any midly advanced computer chess games includes a MinMax function (or its unique call merging sister function NegaMax) called recursively evaluating both sides' possible moves and trying to minimize loss whilst maximizing captures : each evaluation pair rundown is called a "ply" in chess jargon. It can take Kasparov some 27 moves to battle a 3-ply and the champion programs competing with grandmasters usually have at least 5-ply. In the case of BootChess there is alas not enough space (512 bytes binary program size and 640 bytes RAM execution environment) for such level of sophistication. It uses a variant : while maximizing captures it tries to minimize the taxi/Manhattan distance to the opponent's black king rank. This weaker ai element combination will be named "TaxiMax" for the occasion and can be viewed as a half-ply plus."


Very nice to see that the RSi guys (who I have been a fan of since the begin 90s; especially the Amiga stuff was very impressive, both in skill but also art) still take challenges like this one. Disadvantage here is that whenever I click a Pouet.net link, I can pretty much say farewell to my productive day...


With such a small number of bytes wouldn't it be viable to run some sort of optimization to minimize the code even further?


Does it run on a ZX81? If not I'd guess it might be using short cuts not available on the original machine.

Easy way to get them smaller and be legitimate chess (This seems to be missing half the rules) would be let white move, then resign. You might have to allow white to resign / offer a draw as a move as well.


That would include 1) rules for the movement 6 chess pieces 2) board definition and initial setup 3) end conditions 4) exceptions. A tweets lenght worth of each, neat.


"Exceptions"??


Oh ! and this one is a PC boot sector. Sexy


reminds me of the runner-up in the first js1k competition (even better): http://js1k.com/2010-first/demo/750


WTF??? What is that page?


Yeah, well this guy can launch a GUI in zero bytes! Beat that!

http://www.pouet.net/prod.php?which=18860




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: