Author: Robert Hyatt
Date: 11:33:38 11/23/99
Go up one level in this thread
On November 23, 1999 at 12:17:10, José Carlos wrote: > I've just finished a first try of opening book for my program. I've made it >"by hand", but I'd like to read a pgn file to build the book. The problem is >converting SAN to long algebraic notation (d2d4 g8f6 etc...) that my program >understands. > I've tried it myself, considering all cases, but it is hard. I know crafty >reads pgn files, but I can't understand the code very well. So my question is, >is there any free stuff for converting SAN into long algebraic? Or is there any >way to automatically (maybe crafty does?) convert a pgn file into a "pgn with >long algebraic"? or something similar? > > Thanks in advance. > > José C. Why not simply parse SAN rather than the cheesy long algebraic move format? It is easy: generate all possible moves and put them in a list. Remove the illegal moves by making each move and determining if it leaves the side on move in check, which would be illegal. Now take a SAN move and break it up into its component parts: there is _always_ a destination square so find the last occurrence of e4 or something similar (unix regular expression: [a-h][1-8] if you know what that means..) Go thru your move list and remove any move that doesn't have this square as a destination square. Check the first character to see if it is a valid piece. If it is, remove all moves that are for any other piece but the one given. If no piece is given, remove all non-pawn moves. All you have left are a few special cases, like castling (O-O and O-O-O, and _please_ use capital-O and not a zero, to adhere to the PGN standard), the + (check indicator) and finally a promotion piece (which should be =Q or whatever, but is often given without the =). If you use the string to cull moves that can't possibly be valid, you should end up with 1 move left on the list. That is it. If you end up with more than one, the move you read was ambiguous (Nf3 where there is a knight on g1 and g5 for example). If you end up with no moves left, the move given is illegal. All that is left is to handle moves like N1f3 (the 1 must be the source rank) or Ngf3 (the g must be the source file). It isn't hard to do this. You can find code already written in "input.c" in the crafty source. Just call _your_ move generator to produce the list of moves, and use my code to parse/eliminate the moves based on the input characters... Then you can handle nice input rather than requiring e2e4 which I hate. You can use this module to write a SAN output as well. Take the moving piece plus the destination square (and make moving piece blank if it is a P) then pass that to the move input routine to test to see if it is a legal SAN move. If you end up with exactly 1 move in the list, this move is 'ready'. If not, it must be ambiguous, so try adding the source rank and try again. If that works, you are done, otherwise remove the source rank and try the source file. you get the idea... then you can produce SAN output that nobody has problems reading...
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.