X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=Position.pm;h=777571e121d1ba5fc7301d54a6a6b7e1926cb202;hp=7834ca065185ad005be02cf06d252756b08dd3ae;hb=7463b32c4c0a899e591a90d365761ee670c6eb0f;hpb=8fcd3d2321344017e376668cb5d1f5ea7cb47c20 diff --git a/Position.pm b/Position.pm index 7834ca0..777571e 100644 --- a/Position.pm +++ b/Position.pm @@ -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;