$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];
+ $pos->{'prettyprint_cache'} = {};
bless $pos, $class;
return $pos;
sub to_json_hash {
my $pos = shift;
- my $json = { %$pos, board => undef, fen => $pos->fen() };
+ my $json = { %$pos, board => undef, prettyprint_cache => undef, fen => $pos->fen() };
if ($json->{'player_w'} =~ /^base64:(.*)$/) {
$json->{'player_w'} = MIME::Base64::decode_base64($1);
}
return $pos->{'board'}->parse_pretty_move($move, $pos->{'toplay'});
}
+sub num_pieces {
+ my ($pos) = @_;
+ return $pos->{'board'}->num_pieces();
+}
+
# Returns a new Position object.
sub make_move {
my ($pos, $from_row, $from_col, $to_row, $to_col, $promo) = @_;
$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;
}