Chess: Validating moves and commentary using XSLT.

After reading Michael Kay's Knights Tour (XSLT 2nd Edition), Max Froumentin's An XSLT stylesheet for ChessGML and attempting The Times Winning Move over a couple of pints with a chess playing friend. I wanted to validate chess moves using XSLT and create an interactive chess board to input moves using SVG. Here is the work in progress, there is plenty of room for improvement some of which would be focused towards increasing the speed of execution.

What's needed

Requires MSIE (6.0), the Adobe SVG plug-in

Try these

Chess.htm: Allows user to move both White and Black pieces in accordance to the rules of chess. By default, when a piece is selected those squares to which the piece can move are highlighted blue, if a capture is possible then the square is highlighted in green.

Problem.htm: An interface to a set of chess problems. Allows the user to solve selected chess problem with undo move functionality and move commentary.


How it works : Chess.htm

What it does

Allows user to move both White and Black pieces in accordance to the rules of chess. By default, when a piece is selected those squares to which the piece can move are highlighted blue, if a capture is possible then the square is highlighted in green.
By selecting the radio button All possible moves and pressing button Set Parameters, all the squares that it is possible for the active player to move to are highlighted as above.
Checking checkbox Include covering own pieces and setting parameter causes the pieces covered by the selected piece or any of focus players pieces are highlighted red.
If prior to making first move the checkbox Show Commentary is checked, on completion of move the commentary of move is shown (this slows the process down).

How it does it

Onload a reference to the embedded makechess.svg is made and the files game.xml, commentary.xsl and chess.xsl and loaded in to DOMDocument objects. Initialisation of parameters in chess.xsl are set, game.xml and chess.xsl are then transformed, the result is loaded into the existing game.xml DOMDocument. The resulting XML has three elements representing When the active player clicks on one of his pieces the game.xml and chess.xsl DOMDocuments are again transformed and cached in the game.xml DOMDocument (this process is repeated throughout). The resulting XML has the same three elements The active player then selects a destination square by either clicking on a square or piece, the transformation process is repeated. If the move was illegal then the Validation element will have an error attribute and instructions to clean board. The Moves and Squares elements remain unchanged.
If the move is a valid one then The game.xml and commentary.xsl are transformed to output the commentary in HTML.

Acknowledgements

Thanks to Max Froumentin for allowing me to use the SVG chess font (Chess Sophia), without which I would never have started and for his advice and encouraging words.

Disclaimer

Information on this Site may contain inaccuracies - start positions, solutions, commentary etc.

This site has not reviewed any or all of the web sites linked to this Site and is not responsible for the content of any off-site pages or any other web sites linked to this Site. It is the user's responsibility to take precautions to ensure that whatever is selected is free of such items as viruses, worms, Trojan horses and other items of a destructive nature.

Licence

The ChessGML/SVG stylesheets are released under the W3C Software Notice and License.

Bugs and comments welcome at pw@interfootball.co.uk