February 24, 2010

Here's my first try with posting real analysis using the game viewer.

This position occurred toward the end of the game Hill-Rotter from the
opening Capital District League match of the season, between Uncle Sam Troy
and Schenectady 'A'. It's an interesting theoretical ending in which both
players made errors, though it should be noted that the final result of 0-1 is
still just, since Black's mistake didn't give his opponent quite enough for a

Update 2/25/10: The 13 x 6 shape caused by bad FEN has been fixed. Thanks to Chess Teacher for that tip. Next major point of concern is parsing of PGN annotation marks. My source tells me that's going to be worked on for a future release. Hopefully that happens soon! This is a great resource which would be improved yet more with full PGN parsability.

Update 2/26/10: In the meantime, I've bitten the bullet on this occasion and manually put in all of the commentary marks that are practical. Also fixed another little detail in the FEN pointed out by Chess Teacher.

So at this point, this should all work reasonably well! Behold:

February 21, 2010

Code snips for the game displays with the chess game viewer.

All of this is derived from the author's posts at http://chesspublishing.blogspot.com/ . Credit to same is hereby given for all of what follows.

Put everything on a single line in each case--there should be no line breaks anywhere in the SCRIPT command.


This is the basic syntax for game display.

<script language="JavaScript" type="text/javascript">Game('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR 1','sc@@K[@@z^@@@Q@@|a@@ET@@^L@A','1.e4 e5 2.Qh5 Nc6 3.Bc4 Nf6 4.Qxf7# 1-0',1,6);</script>

This means:

the SCRIPT tag for Java;

then the 'Game' function to call up the viewer. I will list the arguments of this function in order. Each is bracketed by single quotes:

1. FEN of the initial position, with the number of the initial move at the end;

2. the coded moves from Palview output;

3. the raw PGN body;

4. [optional] tag for displaying the player-to-move circle pertinent to the position in the diagram (0=none, 1=White to play, 2=Black to play)--here it is set to 1;

5. [optional] the number of ply following the initial position after which to display the diagram position and the initial move for the viewer. Here, it is set to 6, so the diagram will start after Black's 3rd move (6 ply into the game from the initial FEN position).

And finally, the bracketing command tag.



Here is syntax for a game with formatted text. Note that Blogspot may have problems producing this formatting! I had to strip it all out of the code to get acceptable HTML, which is why none of it shows up in the output below.
<script language="JavaScript" type="text/javascript">Game('','sc@@K[@@}l@@@Q@@|a@@DY@@qi@@JR@@ETA@rbA@[bADibADY`AB{}@prbA@[bADibADY`ABET@@rb@@[b@Dib@DYP@@vn@@Tc@@|{@@RZ@@aZ@@BZ@@xi@@ZB@@{c@BQK@@zs@@AS@@A\\A@y]@@BR@@]K@@CK@@bZ@@FB@Dl]@@IQ@@]S@@LS@DcS@BRS@@sS@BKD@@ZR@@BC@@S\\@BDE@@ic@@CD@@\\S@BEF@@c]@@Pt@BDtA@}v@@?C@D]L@BFE@@LV@BEF@@SE@BDE@@VL@A','1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 {<p>The Giuoco Piano Variation of the Italian Opening. This often results in rather boring games, but this game has an interesting ending.</p>} 4.c3 d6 {<p><i>}( 4...Nf6 5.d4 exd4 6.cxd4 Bb4+ {is played more frequently}){</i></p>} 5.O-O ( {<i>Just like} 5.d4 exd4 6.cxd4 Bb4+ {</i>}){<br /><br />} 5...Nf6 6.d4 exd4 7.cxd4 Bb6 8.h3 Nxe4 9.Re1 d5 10.Bxd5 Qxd5 11.Nc3 Qd8 +/- 12.Rxe4+ Ne7 13.Qe2 Be6 ( 13...Bf5! ) 14.Bg5 Qd6?! +- 15.Bxe7!! {<font color="red">and now Black is in trouble!</font><br /><br />} 15...Kxe7 16.d5 Rhd8 17.Ng5 c6 18.Nxe6 fxe6 19.Rxe6+ Qxe6 20.Qxe6+ Kf8 21.d6 Re8 22.Qf5+ Kg8 23.Ne4 Rf8 24.Qe6+ Kh8 25.Ng5 Bxf2+ ( 25...Rxf2 {would have been better, but not enough to share the point} ) 26.Kh2 Rae8? {<br /><br />and now it\'s a Mate in four.} 27.Nf7+! Kg8 28.Nh6+ Kh8 29.Qg8+ Rxg8 30.Nf7# 1-0',1,6);</script>

The function has the same arguments as in the simple case above, with a couple of refinements:

Note that the first argument of the 'Game' function is blank ('' = two single quotes, no space between). This can be done when the starting position for display is the initial position of the chessboard.

The author has formatted the text of his PGN with breaks, font tags, etc. Note that certain additional edits to the PGN may be required for correct parsing of the text, so that Java does not mistakenly interpret certain characters as code (e.g. the leading backslash for display of single quotes).



Here is how to handle a game displayed in parts, with multiple boards to cover each portion.

<script language="JavaScript" type="text/javascript">Game('','sc@@K[@@}l@@@Q@@|a@@DY@@qi@@BK@@{}@pJR@@rb@@YP@@y]@@vnA@ETA@|{A@CEApy]A@NVA@]fA@ET@@o_@@GO@@aZ@@Q@@@xr@DIQ@@Zo@@Ae@@CEApzh@@PG@@hz@@b[ADR[ADl[A@MU@@','1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 4.c3 Qe7 {The Closed Variation of the Giuoco Piano.} 5.O-O d6 6.d4 Bb6 7.Bg5 ( {The main variation is something like} 7.h3 Nf6 8.Re1 O-O 9.Bg5 h6 10.Bh4 ) 7...Nf6 8.a4 a6 9.Bd5 Nb8 {Btw this is the game Polerio-Lorenzo played in 1575} 10.Nbd2 c6 11.Ba2 Bg4?! ( 11...O-O {would have been better} ) 12.Qb3! Ba7 13.Qd1?! ( 13.dxe5! dxe5 14.Nxe5 {and note that Black can not take the white knight, because this will probably result in the loss of the pawns at f7 and g7 and the Rook.} ) 13...g6?! {Only weakens Black\'s position}',1,8);Game('rn2k2r/bp2qp1p/p1pp1np1/4p1B1/P2PP1b1/2P2N2/BP1N1PPP/R2Q1RK1 14','b[@DR[@DoL@BraA@CB@@CLA@raA@elA@zlA@l[@@K[@@]T@BBA@@[TA@ze@B@J@@TF@@[F@@LS@@FC@@ra@@AI@@ed@BIB@@dR@@G@@@RJ@BCJ@@SJ@@BJ@@aP@BJR@@P?@@@G@@|z@FRY@@zb@@OW@@wz@DHX@@p`@BW`@Di`@E','14.dxe5 dxe5 15.Bxf7+? ( 15.Nc4! {would have been a good move} ) 15...Kd8 +- ( {Better to take the piece and play} 15...Kxf7 16.Nc4 Bxf3 17.Qxf3 -/+ ) 16.Nxe5 Qxe5 17.Bxf6+?? Kc8?? ( {It is completely unclear to me why Black doesn\'t play} 17...Qxf6 {after which the position is about equal.} ) 18.Qxg4+ +- {Now White has a decisive advantage.} 18...Nd7 19.Bxh8 Qxh8 20.Be6 Qe8 21.Nc4 Kc7 22.Qf4+ Kd8 23.Qd6 Bb8 24.Qxd7+ Qxd7 25.Bxd7 Kxd7 26.Nb6+ Kd6 27.Nxa8 Ba7 28.Rfd1+ Kc5 {and now the mate is inevitable} 29.Rd4 a5 30.Rad1 b5 31.b4+ axb4 32.cxb4# 1-0',1,1);</script>

This sort of thing is intended for use with lengthy or extensively annotated games.

The 'Game' function is called twice. Obviously, the first chunk of the game can be coded without requiring any alteration except to truncate the game before entering its PGN into Palview. For the second portion, though, one requires the FEN of the starting position at the cut for entry as a presumably independent input into Palview. The output of this position and PGN (the string for the coded moves) then necessarily bears no relation to that featured in the first function call. So one presumably cannot simply drop a complete game into Palview, then expect to be able to separate the coded moves into parts corresponding to one or another piece of the original game.

Note that in the second call, the initial move number is 14, corresponding to the move at which the game score is to be divided.



An example of a training exercise for the reader including solution.

<script language="JavaScript" type="text/javascript">Game('8/p7/1N3K2/Qn3N2/2P1kp2/p3p3/2P1B2b/4n3 1','W_@@GP@DXRQ@_QAAXbQ@\\RAAXiQ@_CAA{qQ@_qAA{lQ@sjAA{jQ@qjAE{uQ@aXAE_?@A','{A mate in two problem. It is White\'s turn to move.}1.Qa4 axb6 ( 1...Nd6 2.Qc6# ) ( 1...Nd4 2.Nd6# ) ( 1...Nc3 2.Qe8# ) ( 1...Nxc2 2.Qxc2# ) ( 1...Nf3 2.Bd3# ) ( 1...Nd3 2.cxd3# ) ( 1...Ng2 2.cxb5# )2.Qa8# 1-0',1,1,5,"Mate in two");</script>

<noscript>Mate in two: 8/p7/1N3K2/Qn3N2/2P1kp2/p3p3/2P1B2b/4n3 w</noscript>

I am not sure of the purpose of the NOSCRIPT line in the source. The author may have used that for his FEN viewer, but it seems unnecessary for the display of the exercise. Whatever it is, the FEN in that statement matches the FEN of the initial position used in the game viewer.

Note the presence of two additional arguments in the 'Game' function for an exercise/problem:

6. the number of tries that the reader must attempt before the solution is revealed (in this case, five);

7. initial diagram caption.


New test.

Test of a diagram viewer. This is the one described at
http://chesspublishing.blogspot.com/2009/10/how-to-configure-fen-viewer.html .