
ChessBoardJS - ca98am79
http://chessboardjs.com/?utm_source=javascriptweekly&utm_medium=email
======
ridiculous_fish
A while back, I attempted to write a chess site that let you paste in chess
games in PGN text format, and then step through them. What I found was pretty
shocking: the PGN format looks simple, but is remarkably difficult for a
computer to parse.

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...](http://www.saremba.de/chessgml/standards/pgn/pgn-
complete.htm#AEN242) .

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.

~~~
chrisoakman
This is a great write-up and is exactly the reason that ChessBoard is "just a
board".

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](https://github.com/jhlywa/chess.js)

~~~
thingsilearned
I created this board a while ago that is connected to that chess.js

[http://thingsilearned.com/projects/chess/](http://thingsilearned.com/projects/chess/)

------
kristopolous
reminds me of the js1k/2010 #2 winner:
[http://js1k.com/2010-first/demo/750](http://js1k.com/2010-first/demo/750)

This one is playable.

~~~
sneak
[https://en.wikipedia.org/wiki/List_of_burn_centers_in_the_Un...](https://en.wikipedia.org/wiki/List_of_burn_centers_in_the_United_States)

~~~
Kiro
I don't understand.

~~~
gamegoblin
In American English, slang for an insult is a "burn".

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.

------
defrex
This project needs a better example on the homepage, I think.

This one is interesting:
[http://chessboardjs.com/examples#3004](http://chessboardjs.com/examples#3004)

~~~
notjustanymike
Agreed, it demonstrates that you could theoretically animate an entire chess
game with a setInterval.

~~~
chrisoakman
Funny; I actually built a demo that did this for the homepage, but decided it
was too complex and scrapped it for later.

------
gidan
Nothing related but see: [http://lichess.org/](http://lichess.org/) (source
code [https://github.com/ornicar/lila](https://github.com/ornicar/lila))

~~~
johnwards
Also has the _best_ CAPTCHA ever.
[http://en.lichess.org/signup](http://en.lichess.org/signup)

~~~
jonnymkramer
Worst CAPTCHA ever. Trivial for a computer to work out, hard for a human.

~~~
aroman
Worst as in least effective, but best as in most amusing.

------
jiggy2011
This doesn't seem to actually play chess.

~~~
twistedpair
Not much to see here. Why is this JS? Usually JS requires some interaction.
Even lightbox flew around and did something. This would be even easier as a
chessboard PNG rendering REST service.

~~~
chrisoakman
ChessBoard supports drag-and-drop pieces:
[http://chessboardjs.com/examples#2006](http://chessboardjs.com/examples#2006)

------
moron4hire
Mine from a decade ago is suitable for play-by-email [http://wedusc.com/web-
chess/?7567](http://wedusc.com/web-chess/?7567)

------
mapleoin
Awesome, I have something similar for the game of Go:
[https://github.com/mapleoin/goboard.js](https://github.com/mapleoin/goboard.js)

Unfortunately I didn't spend that much time writing beautiful docs for it.

------
chrisoakman
Hi; this is a pleasant surprise :)

I wrote this component. Happy to answer questions, feedback, etc.

------
oakaz
Pure HTML Chess Board with FEN support;
[http://azer.github.io/chessboard/initial.xml](http://azer.github.io/chessboard/initial.xml)

------
dm2
There is also this game:
[http://multiplayerchess.com/](http://multiplayerchess.com/)

------
kayoone
Should be fairly easy to make this understand the basic movements. Add some
node-js multiplayer and off you go.

~~~
AnIrishDuck
I actually built almost exactly this on top of dotcloud a while back:

[http://chessjs-anirishduck.dotcloud.com/new](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/...](https://github.com/AnIrishDuck/chess.js/blob/master/chessjs/static/js/rules/base.js)

------
tvtime15
When's the Chinese checkers edition coming out?

------
ROI_ninja
anyone looked at [http://bookmarkchess.com/](http://bookmarkchess.com/)

