Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Just another Perl shrine
 
PerlMonks  

Re: Parsing Chess Algebra Notation

by davidj (Priest)
on May 14, 2004 at 13:26 UTC ( [id://353424]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Parsing Chess Algebra Notation

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://353424]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.