ChessBoardJS
chessboardjs.com
chessboardjs.com
The reason is that the PGN format only specifies the piece type and destination square of each move. Ne4: a knight moves to e4, and it's up to the parser to figure out which knight. So to parse PGN, you have to teach your parser how the pieces move.
That by itself is not too bad, but it gets worse. What if both knights can move to e4? Then the format disambiguates. Nge4: the knight on the g file moves to square e4. But "can move" is a tricky notion in chess. This knight cannot move because it is pinned to the king. That pawn can capture en passant this turn, but not next turn. So to write a PGN parser, you must build a chess engine capable of analyzing a board sufficiently to determine legal moves.
One might hope that reasonable PGN text would be nice and disambiguate whenever two pieces attack the same square, and not require legal move analysis. Alas, it is not so. The "two knights attack a square but one is pinned" case is specifically called out as NOT requiring disambiguation in the spec at http://www.saremba.de/chessgml/standards/pgn/pgn-complete.ht... .
A further consequence is that it is not possible to make a "generic PGN" parser that can handle chess variants, like suicide chess. The rules of chess are baked into the format itself, and the parser must have knowledge of the rules used to play the game that it is presenting.
Proper PGN parsing and legal move validation is a complex and independent problem that nicely fits into it's own library and should be separate from any display logic.
For example: https://github.com/jhlywa/chess.js
Check out chess.js, https://github.com/jhlywa/chess.js, it does a pretty excellent job. The combination of chessboard.js and chess.js would result in a pretty sweet browser-based chess game.
This one is playable.
[0] http://malevolent.com/weblog/archive/2010/09/07/1k-chess-sho...
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()I am not a javascript expert. but given the size of the code, I doubt there is a great IA underluying. Actually I've browsed the mignified code in order to find the AI implementation. The only clue I spot was a call to the Random() function. I won't state it for sure, because I wasn't able to understand the whole code. But I highly guessed it is the basis of the AI implementation. :-)
On a less painful note, these types of scripts that do so much with so little are exactly the type of problem that interest me. I don't even care that I was beaten; I just love the fact that something like this exists.
Just goes to show how algorithmic chess can be. And code, no matter how "primitive" will trump neurons when it comes to algorithms.
e.g.
"You got burned" = "You were insulted"
The poster was making a joke that the OP had been insulted because this other JavaScript board is superior or something, hence, he directed him to treatment centers for a "burn".
This is very common on reddit.
This one is interesting: http://chessboardjs.com/examples#3004
I had always wanted to build the board as a separate component.
It is in a similar vein to this: http://andrewphoy.github.io/chess-replayer/. (Which is more full-featured.)
https://github.com/oakmac/chessboardjs/blob/master/README.md
I have an issue to build an example that demonstrates integration with chess.js and only allows legal moves (https://github.com/oakmac/chessboardjs/issues/19)
Unfortunately I didn't spend that much time writing beautiful docs for it.
I wrote this component. Happy to answer questions, feedback, etc.
http://chessjs-anirishduck.dotcloud.com/new
I initially based it off a wild idea my coworker and I had about a chess variant where any piece that captures another piece has the option of becoming that piece. I then expanded it with several other chess rule variants, including vanilla chess.
One thing worth mentioning is that the rules for chess are deceptively complex. Especially when it comes to valid moves avoiding check and moving out of check. See:
https://github.com/AnIrishDuck/chess.js/blob/master/chessjs/...