Chess in 1024 bytes

Discussion in 'Programming' started by G.N.C., Oct 13, 2012.

  1. #1
    Miracle of optimization:
    <canvas id="c"></canvas>           <script>for(B=i=y=u=b=i=5-5,x=10,I=[],l=[];B++<304;I[B-1]=B%x?B/x%x<2|B%x<2?7:B/x&4?0:l[i++]="ECDFBDCEAAAAAAAAIIIIIIIIMKLNJLKM@G@TSb~?A6J57IKJT576,+-48HLSUmgukgg OJNMLK  IDHGFE".charCodeAt(y++)-64:7);function X(c,h,e,s){c^=8;for(var o,S,C,A,R,T,G,d=e&&X(c,0)>1e4,n,N=-1e8,O=20,K=78-h<<9;++O<99;)if((o=I[T=O])&&(G=o^c)<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^c)>9&&G|A>2){if(!(R-2&7))return K;n=G|(c?T>29:T<91)?o:6^c;S=(R&&l[R&7|32]*2-h-G)+(n-o?110:!G&&(A<2)+1);if(e>h||1<e&e==h&&S>2|d){I[T]=n;I[O]=0;S-=X(c,h+1,e,S-N);if(!(h||e-1|B-O|T-b|S<-1e4))return W(),c&&setTimeout("X(8,0,2),X(8,0,1)",75);I[O]=o;I[T]=R}if(S>N||!h&S==N&&Math.random()<.5)if(N=S,e>1)if(h?s-S<0:(B=O,b=T,0))break}while(!R&G>2||(T=O,(G||A>2|(c?O>78:O<41)&!R)&&++C*--A))}return-K+768<N|d&&N}function W(){i="<table>";for(u=18;u<99;document.body.innerHTML=i+=++u%x-9?"<th width=60 height=60 onclick='I[b="+u+"]>8?W():X(0,0,1)'style='font-size:50px'bgcolor=#"+(u-B?u*.9&1||9:"d")+"0f0e0>&#"+(I[u]?9808+l[67+I[u]]:160):u++&&"<tr>")B=b}W()</script>
    Code (markup):

     
    G.N.C., Oct 13, 2012 IP
  2. rain112

    rain112 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Looks good, did you code it yourself ?
     
    rain112, Oct 13, 2012 IP
  3. G.N.C.

    G.N.C. Member

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #3
    No, it's not my code.
    ---
    Example:
    goo.gl/NFF2r
    My modification, еspecially for Chuck Norris:
    goo.gl/YMEoT
     
    G.N.C., Oct 13, 2012 IP
  4. rain112

    rain112 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I just checked it out briefly and WOW ! I'm seriously impressed. So much into 1 KB. I've been into JS for quite a bit of time but never have I seen something like this ! Thanks a lot for sharing this :)
     
    rain112, Oct 14, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    If you're interested in that sort of thing, look into old code repositories. Sargon was written to run in the old Kim single-board in 1k. (The computer had only 1k of RAM.) And there was a Krell chess program that ran in IIRC 4k (in the old TRS-80).
     
    Rukbat, Oct 14, 2012 IP
  6. G.N.C.

    G.N.C. Member

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #6
    By the way is not the smallest chess program.
    1K ZX Сhess - smallest chess program
     
    G.N.C., Oct 15, 2012 IP