[antlr-interest] Parsing PGN (chess algebraic notation) files

Edson Tirelli ed.tirelli at gmail.com
Mon Jan 24 19:29:10 PST 2011


   Just keep a Map with each piece and current position, updating it as you
parse. It is simpler than you think. At least, that is how I would do it, as
it is not that different than tracking variables in a regular program. Since
the PGN is assumed to be correct, you will also have no problems with
conflicts, since whenever 2 pieces of the same type can move to the same
destination, the PGN notation will tell you which one is moving there. Ex:



2011/1/24 Kevin Jackson <foamdino at gmail.com>

> Hi,
> I have to convert PGN files using algebraic notation and I'm doing ok so
> far.
> I have one major stumbling block and I was wondering if anyone has
> done something similar.
> Algebraic notation is a short form of chess move that only contains an
> optional piece identifier, followed by destination square followed by
> optional markers:
> e5 => pawn moves to e5
> Bf3 => Bishop moves to f3
> Nh2+ => Knight moves to h2 (and check)
> Parsing these is ok, but my task is to generate output containing both
> start and end positions for a move.  My research seems to indicate
> that this isn't easy without maintaining the current state of the
> board and applying each move as I parse it to update the board and
> therefore be able to determine where the move came from.  Another
> option is to maintain an index of piece-destination
> (possible_start_position_1, possible_start_position_2...) - and then
> for each piece lookup where it could possibly have come from - I'm not
> sure this helps though :)
> What was a simple text transformation problem has become a game engine!
> I'd be interested to hear any thoughts from people who have attempted
> PGN parsing in antlr
> Thanks,
> Kev
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address

  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com

More information about the antlr-interest mailing list