Think about Loose Coupling | |
PerlMonks |
Re: Parsing Chess Algebra Notationby davidj (Priest) |
on May 14, 2004 at 17:26 UTC ( [id://353424]=note: print w/replies, xml ) | Need Help?? |
If all you want to do is parse the individual moves (without validating, etc), the following regex will do the trick: ($p, $f, $r, $a, $d, $c) = $move =~ /([BKNPQR]?)([a-h]?)([0-9]?)([x=]?)([BKNPQR]|[a-h][1-8])([+#]?)/; where the variables are as follows: $move = the move being parsed $p = the piece being moved $f = the file being moved from $r = the rank being moved from $a = action (x = capture, '=' = promote) $d = destination square (or promotion piece if $a = '=') $c = check or mate As an example, the move you gave, Nf4, will parse as follows: $p = N, $f = "", $r = "", $a = "", $d = b4, $c = "" hope this helps, davidj
In Section
Seekers of Perl Wisdom
|
|