From: Steinar H. Gunderson Date: Fri, 5 Sep 2014 05:12:17 +0000 (+0200) Subject: Fix last_move_uci for PGN loads. X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=2ec5e8902926f0e192fb119f3955dab2564816aa;hp=aab426550a1da4daea35eb0b0691fe8bd7907348 Fix last_move_uci for PGN loads. --- diff --git a/Board.pm b/Board.pm index d6a0f55..ff2828a 100644 --- a/Board.pm +++ b/Board.pm @@ -36,7 +36,7 @@ sub clone { # Returns a new board. sub make_move { my ($board, $from_row, $from_col, $to_row, $to_col, $promo) = @_; - my $move = _move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo); + my $move = move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo); my $piece = $board->[$from_row][$from_col]; my $nb = $board->clone(); @@ -144,7 +144,7 @@ sub _square_to_pos { return (_row_letter_to_num($2), _col_letter_to_num($1)); } -sub _move_to_uci_notation { +sub move_to_uci_notation { my ($from_row, $from_col, $to_row, $to_col, $promo) = @_; $promo //= ""; return _pos_to_square($from_row, $from_col) . _pos_to_square($to_row, $to_col) . $promo; @@ -447,7 +447,7 @@ sub prettyprint_move { sub _prettyprint_move_no_check_or_mate { my ($board, $from_row, $from_col, $to_row, $to_col, $promo) = @_; my $piece = $board->[$from_row][$from_col]; - my $move = _move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo); + my $move = move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo); if ($piece eq '-') { die "Invalid move $move"; diff --git a/Position.pm b/Position.pm index 371e179..9868b21 100644 --- a/Position.pm +++ b/Position.pm @@ -29,6 +29,11 @@ sub new { $pos->{'player_w'} =~ s/^W?[FCIG]M//; $pos->{'player_b'} =~ s/^W?[FCIG]M//; $pos->{'move_num'} = $x[26]; + if ($x[27] =~ /([a-h][1-8])-([a-h][1-8])/) { + $pos->{'last_move_uci'} = $1 . $2; + } else { + $pos->{'last_move_uci'} = undef; + } $pos->{'last_move'} = $x[29]; bless $pos, $class; @@ -179,6 +184,8 @@ sub make_move { $np->{'player_b'} = $pos->{'player_b'}; my ($move, $nb) = $pos->{'board'}->prettyprint_move($from_row, $from_col, $to_row, $to_col, $promo); $np->{'last_move'} = $move; + $np->{'last_move_uci'} = Board::move_to_uci_notation($from_row, $from_col, $to_row, $to_col, $promo); + return bless $np; }