6 ms·
This is a fully working chess program with graphics. In 1024 bytes of JS. o_0
- deleted 16y ago[deleted]
- adamtj 16y agoIt's not quite fully working. Either that, or I just can't figure out how to castle. Even so, it's very impressive.
- deleted 16y ago[deleted]
- StavrosK 16y agoIt says in the description that it doesn't support castling or en passant. Also, wtf, the guy wrote a chess program with AI in 1 kb and you're complaining about castling?
- CGamesPlay 16y agoThe title here on HN is "fully working", which isn't true.
- adamtj 16y agoAgreed, I wasn't complaining, I was just pointing out a minor inaccuracy in the title. It's very impressive and doesn't need to be oversold.
- kiiski 16y agoCastling is pretty important move in chess. You can hardly claim an implementation to be fully working without it (although it wasn't the author claiming that).
- wensing 16y agoI wonder how many characters of code it would take.
- niyazpk 16y agoThe problem with castling is that for a move that is only once done in a chess game we have to keep track of a couple of variables and do a check for every move in the tree. It is rather unpleasant to code and it will increase the program size and decrease the speed (by a bit I mean). May be that is because they ended up not implementing castling.
- Isofarro 16y agoit's one of three special cases where it isn't moving a piece from and to a square. The other being capturing enpassant, and queening a pawn. Certainly cannot claim to be complete without being able to play a legal move.
- jpwagner 16y ago...promoting a pawn ...and then there's the 50 move and repetition draws ...and a non-chess player may not realize how vital a knowledge of openings is but it basically works
- StavrosK 16y agoLooks like someone just won the contest...
- phoboslab 16y agoChess is damn impressive, but so is Tetris ( http://js1k.com/demo/663 http://js1k.com/demo/663 ) or a Jump'n'Run ( http://js1k.com/demo/635 http://js1k.com/demo/635 ). There are also a lot of very beautiful graphic demos like http://js1k.com/demo/171 http://js1k.com/demo/171 or http://js1k.com/demo/49 http://js1k.com/demo/49 Shameless plug: My syntax highlighting Quine: http://js1k.com/demo/223 http://js1k.com/demo/223
- StavrosK 16y agoJesus, those are all amazing. It was very nice of the Jump'n'Run guy to include the commented source.
- cakeface 16y agoI really like this one too http://js1k.com/demo/12 http://js1k.com/demo/12
- AndyKelley 16y agoSyntax highlighting Quine is great! Although quine part was pretty easy :P
- julian37 16y agoHe won the IOCCC a number of times before. http://nanochess.110mb.com/ http://nanochess.110mb.com/
- dsplittgerber 16y agoBrilliant. Reminds of the old 4k demo competitions - craft at its best.
- mechanical_fish 16y agoIt reminds me of Atari 2600 chess, which used to be able to beat me [1] using 4k of ROM and 128 bytes of RAM [2]. --- [1] This is not a particularly remarkable achievement even today, of course. [2] Note to people younger than twenty: this is not a typo.
- SageRaven 16y agoI used to get repeatedly trounced by "Video Chess" on the TI-99/4A. Don't know how large that game was, but being from '79 it couldn't have been that large. Not that I was (or am) any good at chess -- if I fired up that game under MESS today it would probably still trounce me.
- deleted 16y ago[deleted]
- halo 16y agoReminded me of 1k ZX Chess (http://en.wikipedia.org/wiki/1K_ZX_Chess http://en.wikipedia.org/wiki/1K_ZX_Chess), an implementation of chess with AI for the ZX-81, a home computer which had a whopping 1k of RAM.
- caf 16y agoThat's actually a more impressive achievement, since Z80 assembler is far less expressive than Javascript. And all the display output had to be in that, too!
- pella 16y ago...only 672 bytes. source code: http://users.ox.ac.uk/~uzdm0006/scans/1kchess/ http://users.ox.ac.uk/~uzdm0006/scans/1kchess/ and ZX-81 emulator to play the game: http://www.zx81stuff.org.uk/zx81/emulate.php?tzx=0/1KZXChess(Artic).tzx.zip%400&title=White+queen+pawn+moved+from+1K+ZX+Chess http://www.zx81stuff.org.uk/zx81/emulate.php?tzx=0/1KZXChess...
- wensing 16y agoIn case you don't take the time to have your mind blown, here's the source (1014 characters): for(B=i=y=u=b=i=5-5,x=10,I=[],l=[];l[B]="ECDFBDCEAAAAAAAAIIIIIIIIMKLNJLKM@G@TSb~?A6J57IKJT576,+-48HLSUmgukgg OJNMLK IDHGFE".charCodeAt(B)-64,B++<120;I[B-1]=B%x?B/x%x<2|B%x<2?7:B/x&4?0:l[i++]:7);function X(c,h,e,s){e^=8;for(var o,S,C,A,R,T,G,n,N=-1e8,O=20;++O<99;)if((o=I[T=O])&&(G=o^e)<7){A=G--&2?8:4;C=o-9?l[61+G]:49;do if(!(R=I[T+=l[C]])&&!!G|A<3||(R+1^e)>9&&G|A>2){if(!(R-2&7))return 78-h<<x;n=G|(e?T>29:T<91)?o:6^e;S=(R&&l[R&7|32]-h-G)+(G?0:n-o?55:(A<2)+1);if(c>h||1<c&c==h&&S>2){I[T]=n;I[O]=0;S-=X(c,h+1,e,S-N);if(!(h||c-1|B-O|T-b|S<-1e4))return W(B=0),e&&setTimeout("X(2,0,8),X(1,0,8)",50);I[O]=o;I[T]=R}if(S>N||!h&S==N&&Math.random()<.5)if(N=S,c>1)if(h?s-S<0:(B=O,b=T,0))return S}while(!R&G>2||(T=O,(G||A>2|(e?O>78:O<41)&!R)&&++C--A))}return N}function W(){i="<table>";for(u=18;u<98;i+=++u%x-9?"<th width=60 height=60 onclick='I[b="+u+"]>8?W(B=b):X(1,0,0)'style='font-size:50px'bgcolor=#"+(u-B?u.9&1||9:"d")+"0f0e0>&#"+(I[u]?9808+l[67+I[u]]:160)+";":u++&&"<tr>");document.body.innerHTML=i+"</table>"}W(); Beautified: for (B = i = y = u = b = i = 5 - 5, x = 10, I = [], l = []; l[B] = "ECDFBDCEAAAAAAAAIIIIIIIIMKLNJLKM@G@TSb~?A6J57IKJT576,+-48HLSUmgukgg OJNMLK IDHGFE".charCodeAt(B) - 64, B++ < 120; I[B - 1] = B % x ? B / x % x < 2 | B % x < 2 ? 7 : B / x & 4 ? 0 : l[i++] : 7); function X(c, h, e, s) { e ^= 8; for (var o, S, C, A, R, T, G, n, N = -1e8, O = 20; ++O < 99;) if ((o = I[T = O]) && (G = o ^ e) < 7) { A = G-- & 2 ? 8 : 4; C = o - 9 ? l[61 + G] : 49; do if (!(R = I[T += l[C]]) && !! G | A < 3 || (R + 1 ^ e) > 9 && G | A > 2) { if (!(R - 2 & 7)) return 78 - h << x; n = G | (e ? T > 29 : T < 91) ? o : 6 ^ e; S = (R && l[R & 7 | 32] - h - G) + (G ? 0 : n - o ? 55 : (A < 2) + 1); if (c > h || 1 < c & c == h && S > 2) { I[T] = n; I[O] = 0; S -= X(c, h + 1, e, S - N); if (!(h || c - 1 | B - O | T - b | S < -1e4)) return W(B = 0), e && setTimeout("X(2,0,8),X(1,0,8)", 50); I[O] = o; I[T] = R } if (S > N || !h & S == N && Math.random() < .5) if (N = S, c > 1) if (h ? s - S < 0 : (B = O, b = T, 0)) return S } while (!R & G > 2 || (T = O, (G || A > 2 | (e ? O > 78 : O < 41) & !R) && ++C--A)) } return N } function W() { i = "<table>"; for (u = 18; u < 98; i += ++u % x - 9 ? "<th width=60 height=60 onclick='I[b=" + u + "]>8?W(B=b):X(1,0,0)'style='font-size:50px'bgcolor=#" + (u - B ? u.9 & 1 || 9 : "d") + "0f0e0>&#" + (I[u] ? 9808 + l[67 + I[u]] : 160) + ";" : u++ && "<tr>"); document.body.innerHTML = i + "</table>" } W();
- seles 16y agoNice, but it isn't very good, lost to Fools Mate (it took a knight then got mated) (1 look ahead would see it, queen and bishop just attack pawn near king)
- wensing 16y agoFeel free to improve on it.
- wensing 16y agoTitle is wrong: it's 1014 bytes.
- dansingerman 16y agoCan castling and/or en passant be squeezed into 10 bytes?
- ilitirit 16y agoAnyone wanna have a stab at explaining how it works?
- dabeeeenster 16y agoIt's recursive. Probably easier to get your head around the recursive solution to the towers of hanoi (http://en.wikipedia.org/wiki/Tower_of_Hanoi http://en.wikipedia.org/wiki/Tower_of_Hanoi) and then start on the Chess code!
- kenjackson 16y agoI really don't think the recursion is the hard part to understand. It's what each variable and magic number means. A while ago someone had a post of the exponentiation function written with single letter variables. It was difficult to know what it was doing. With proper variable names it would be apparent. I think what people are asking is basically, could someone convert this to a program that is actually meant to be read, while still maintaining its exact control flow and logic.
- michael_dorfman 16y agoMy favorite is still Peter Jennings' Micro-Chess, from 1976, which ran on a KIM-1 (6502) machine and used 1.1K of RAM. http://users.telenet.be/kim1-6502/microchess/microchess.html http://users.telenet.be/kim1-6502/microchess/microchess.html I had the PET 2001 version (which ran in 7K) and played pretty competent chess, all things considered-- disassembling that, back in the day, was a major boost to my software development education.
- eliben 16y agoWell done, but no castling support and the the AI seems pseudo-random :-) Not to take credit from this achievement though, it's a commendable hack!
- pavs 16y agoAs someone who have been involved with chess engine community for the last 15 years or so (not anymore) I can tell you that, until recently, almost every single new engine, that has been written from scratch instead of copying an OS implementation, almost always left out en passant and castling in its first few releases. Even when they did implement those rules in to the engine, they did so grudgingly or as an after thought. I wonder why. Now, everyone just copies the few dozens of OS options available out there and use their move generator which support all the rules, they just tweak with the piece values and algorithm to give a "personal touch" to the engine.
- Twisol 16y agoApparently, I play chess worse than a pseudo-random 1012-byte JS chess bot. Burn...
- joey_bananas 16y ago1024 bytes... and a 60 meg browser.
- iamwil 16y agoYes, and you can play anywhere in the world, on all different operating systems and platforms.
- philjackson 16y agoPlus all of that libc. Not to mention the megabytes of kernel. How big is a bootloader these days?
- antirez 16y agoit's easy to defeat but definitely not random, it will win most of the times against people that just know the rules but rarely played.
- iamwil 16y agoI lost. :(
- daralthus 16y agowell I don't want to be in his place debugging this: http://tinypic.com/r/24zknc9/7 http://tinypic.com/r/24zknc9/7 :D
- pella 16y agosimilar ... http://news.ycombinator.com/item?id=1034359 http://news.ycombinator.com/item?id=1034359
- deleted 16y ago[deleted]
- elblanco 16y agoPerhaps someone should look at modifying this for a 4k competition with good AI and all of the movement rules.
- fizx 16y agohttp://nanochess.110mb.com/chess4.html http://nanochess.110mb.com/chess4.html Much older than this article, but same idea.
- SeanLuke 16y agoCastling is broken.
- Jach 16y agoIt's trivial to defeat with the four-move checkmate, but still an interesting piece of code.
- clueinfool 16y agoHere is a very small program, well-known in chess circles because it plays at nearly 1800 elo, which is good enough to beat strong club players. http://home.hccnet.nl/h.g.muller/max-src2.html http://home.hccnet.nl/h.g.muller/max-src2.html
- jacquesm 16y agoThe 'best' page is really useful sometimes, I completely missed this one. What a gem!
- AndyKelley 16y agoNothing like something like this to come along every now and then and completely destroy my hubris.