
My brother-in-law and I have been playing chess by e-mail for the last few months. This has been less than optimal: we use the old style English notation rather than algebraic notation, and he sets up a real board while I use Apple Chess, so there’s always some transcription from mail to board. Invariably one of us (usually me) gets something wrong, and we end up backtracking through mail history or making a stupid move that we didn’t intend.
We looked at web interfaces for chess by e-mail gateways, and none of them worked out acceptably for both of us. So finally I decided I’d program something. I decided to put together a client side using the Google Web Toolkit; I plan to integrate the back end with Wordpress as a PHP plugin.
The Google Web Toolkit (GWT) is pretty neat, even without diving into all the AJAX/RPC stuff which I might not need for this project. You program the client side in Java, using the GWT-supplied emulation of java.lang, java.util, plus their own classes which provide UI elements and control over the browser object model. During development, the GWT environment runs your code in a Java-enabled hosted browser; once done, it compiles your code into browser-specific Javascript. No Java plugin required.
The result of hacking this weekend: a Chess applet that runs in a browser. The applet itself is about 61 KiB depending on browser, plus 16 KiB for Google-supplied base code. You can play a new game on a blank board here. All chess rules except for pawn promotion are handled, including en passant and castling - you shouldn’t be able to input an invalid move. (If so, it’s a bug! Please let me know.) It should detect check, checkmate, and stalemate (by lack of move) correctly, and the game log should be maintained in proper algebraic notation. The applet can also load a movelist in PGN format (or at least a good subset of it), embedded directly on the web page - for example, here’s Fool’s Mate in 4 moves, view the page source to see the original PGN. For a more interesting problem, here’s Reshevsky vs. Fisher, 1970, black to move and win.
I burrowed the icons from XBoard, themselves generated from a METAFONT font. I noticed Wikipedia has SVG versions derived from same.
The Google Web Toolkit does have a few quirks. No java.util.StringTokenizer, but String.split sort of covers that. It also doesn’t completely cover cross-browser issues. I noticed some differences between regular expression handling (or maybe it was actually newline or whitespace issues in TextAreas), and because of Internet Explorer stupidity (lack of CSS support for min-width), and because I couldn’t figure out how to size an element after an image had guaranteed loading, I couldn’t successfully achieve my goal of getting all sizes and images controlled completely by a style sheet. I still have a ways to go before the client UI is as clean as I want, and with all the chess rules pushed to the client side, it isn’t as optimal as it should be. For example, you may have gotten a script incomplete warning while loading the last page: it’s churning through a lot of possible moves while dealing with PGN notation. Then there’s figuring out how to integrate this all with Wordpress properly. Once this is all done though, David and I can finally be rid of my KP1-KP3 gaffes.