]> git.sesse.net Git - remoteglot/blobdiff - Position.pm
Fix the move prettyprinting on make_move().
[remoteglot] / Position.pm
index 7834ca065185ad005be02cf06d252756b08dd3ae..777571e121d1ba5fc7301d54a6a6b7e1926cb202 100644 (file)
@@ -167,7 +167,8 @@ sub make_move {
        }
        $np->{'player_w'} = $pos->{'player_w'};
        $np->{'player_b'} = $pos->{'player_b'};
-       $np->{'last_move'} = '(move)';  # FIXME
+       my ($move, $nb) = $pos->{'board'}->prettyprint_move($from_row, $from_col, $to_row, $to_col, $promo);
+       $np->{'last_move'} = $move;
        return bless $np;
 }
 
@@ -176,4 +177,34 @@ sub _pos_to_square {
         return sprintf("%c%d", ord('a') + $col, 8 - $row);
 }
 
+sub apply_uci_pv {
+       my ($pos, @pv) = @_;
+
+       my $pvpos = $pos;
+       for my $pv_move (@pv) {
+               my ($from_row, $from_col, $to_row, $to_col, $promo) = _parse_uci_move($pv_move);
+               $pvpos = $pvpos->make_move($from_row, $from_col, $to_row, $to_col, $promo);
+       }
+
+       return $pvpos;
+}
+
+sub _col_letter_to_num {
+       return ord(shift) - ord('a');
+}
+
+sub _row_letter_to_num {
+       return 7 - (ord(shift) - ord('1'));
+}
+
+sub _parse_uci_move {
+        my $move = shift;
+        my $from_col = _col_letter_to_num(substr($move, 0, 1));
+        my $from_row = _row_letter_to_num(substr($move, 1, 1));
+        my $to_col   = _col_letter_to_num(substr($move, 2, 1));
+        my $to_row   = _row_letter_to_num(substr($move, 3, 1));
+        my $promo    = substr($move, 4, 1);
+        return ($from_row, $from_col, $to_row, $to_col, $promo);
+}
+
 1;