|Don't ask to ask, just ask|
Parsing Chess Algebra Notationby cyocum (Curate)
|on May 04, 2004 at 13:33 UTC||Need Help??|
cyocum has asked for the
wisdom of the Perl Monks concerning the following question:
I would like to thank you all in advance for helping me with this.
I am writing a Chess Engine in Perl. I know there are several already on CPAN but they seem to have been abandoned and I was hoping to keep my skills up while I am in grad school.
My question is how do I go about parsing Chess algebra notation? I will give you a few examples. For instance, e4 means "move pawn on e2 to e4." Well this is easy enough but it gets more complicated. Nf3 means "move Knight on g1 to f3". As you can see the piece letter, in this case N for Knight, is not always required. Also, sometimes you get e4xd5 which means "pawn on e4 takes piece on d5". In the case of Rooks, you can get: Rad4, which means "move the Rook which is on column a and move it to d4" (this is in case both rooks can move to d4 legally).
Currently I have this:
It is horrible and not complete and I know it. I was thinking about using split on this but because the first letter is not always the piece letter, it gets confusing.
Again, thanks and any help would be greatly appreciated!