This is a fully working chess program with graphics. In 1024 bytes of JS. o_0
js1k.com
js1k.com
...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
umm...are you saying that when in a position where it's impossible to make a move, it still moves?
Does it not report win/loose? I only played one game.
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.
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...
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.
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();http://en.wikipedia.org/wiki/Chess_symbols_in_Unicode
ps : also it's better to beautifier the code to (try to) understand it :
It's possible to have missing or corrupted Unicode font (once my Arial got broken and I had to get it somewhere from the web).
funny sentence :D
Is there a point in saying 5-5 instead of 0, other than wasting two characters for the fun of it?
[Edit: sibling post explains it.]
- "Biyubi" looks like his nickname (on his chess site [1] contact mail is "biyubi@gmail.com")
- there is also "o, S, C, A, R, T, G" which are his first name and surname initials
- and already mentioned "X(c, h, e, s)"
X(c, h, e, s)
---
[1] This is not a particularly remarkable achievement even today, of course.
[2] Note to people younger than twenty: this is not a typo.
Shameless plug: My syntax highlighting Quine: http://js1k.com/demo/223
Not to take credit from this achievement though, it's a commendable hack!
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.
Much older than this article, but same idea.