Saturday, January 2, 2016

Short Algebraic Notation Madness

Chess games collections are usually stored in PGN and the moves are given in SAN (Short Algebraic Notation). This is meant to make it more readable for a human reader but for a human writer it is sometimes hard to follow the complicated rules especially if he writes the score sheet while playing a game.

For me as a programmer the existence of SAN is also really annoying. LAN (long algebraic notation) would make life much easier. The problem with SAN is the handling of move ambiguity. As usually the source square of a move is not given it must be calculated using the current layout of the board (which piece of the given type can travel to the target square).

So in order to translate SAN into a binary move object with (source and target square) a corresponding board class is needed which implements operations like get me all squares a bishop can travel to from source sq x. What makes it even more difficult is the rules for handling cases when more than one piece can travel to a certain square. Then file or rank of the source square are given, sometimes even both.

But not enough. If two pieces can reach the target square from a source square then the source file or rank indicator rule is not applied if one of the pieces is pinned and cannot move.

A lot of code is needed to handle all the special SAN cases and I estimate that a a fair number of club level written score sheets are not correct either.

So why am I complaining. My just published new books contain some errors as I was not handling the "two pieces can reach the target square but one of them is pinned to the king" case correctly. I fixed my book code and I'm in the process of rebuilding the books now.

So an update is coming soon.