I took your advice and tried it backwards. As you will notice, I did this in a step by step fashion. I am sure that there are much more effient ways to do this. Also, it does not yet support the edge cases that you are talking about (that includes promotion). I just wanted to layout a bit more code for general commments and improvments. Also, thanks for all the help. I really appreciate it!

use strict; use warnings; my $move = "Qe4++"; #reverse as per dragonchild's suggestion my @parsed = reverse split //, $move; print join('', @parsed) . "\n"; my $check; my $row; my $col; my $piece; #convert the letters into appropriate numbers #there is probably a faster way to to this my %col_convert = (a => 0, b => 1, c => 2, d => 3, e => 4, f => 5, g => 6, h => 7); foreach my $elem (@parsed) { #check for, well, check if($elem eq '+') { #start the process to see if this is a checkmate my $nextElem = shift @parsed; print "nextElem $nextElem" . "\n"; #if it is then print if($nextElem eq '+') { print "Checkmate\n"; next; } else { #otherwise put it back on the stack for the next #iteration unshift @parsed, $nextElem; } #then print check in this instance print "Check\n"; }elsif($elem =~ m/[1-8]/) { $row = $elem; print "Row: $row\n"; }elsif($elem =~ /[a-h]/) { #convert to number $col = $col_convert{$elem}; print "Col: $col\n"; }elsif($elem =~ m/x/) { #this is a capture to that square print "Capture on $col $row\n"; }elsif($elem =~ /[KQRNB]/) { $piece = $elem; print "Piece to move is $piece\n"; } else { die "not a valid move\n"; } }


In reply to Re: Re: Parsing Chess Algebra Notation by cyocum
in thread Parsing Chess Algebra Notation by cyocum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.