X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=Position.pm;h=272cadb78d2124275556e16df5bc7403b19cbe6d;hp=807b0035876e3a261dae1f2e0097c371d7160953;hb=65aa4e3d31851a0b504f55ec9907b4fe4f9f8966;hpb=d40118a8adcb0da790ab1087296287e7eeab7c2c;ds=sidebyside diff --git a/Position.pm b/Position.pm index 807b003..272cadb 100644 --- a/Position.pm +++ b/Position.pm @@ -97,6 +97,35 @@ sub fen { return $fen; } +# Returns a compact bit string describing the same data as fen(), +# except for the half-move and full-move clock. +sub bitpacked_fen { + my $pos = shift; + my $board = $pos->{'board'}->bitpacked_fen(); + + my $bits = ""; + if ($pos->{'toplay'} eq 'W') { + $bits .= "0"; + } else { + $bits .= "1"; + } + + $bits .= $pos->{'white_castle_k'}; + $bits .= $pos->{'white_castle_q'}; + $bits .= $pos->{'black_castle_k'}; + $bits .= $pos->{'black_castle_q'}; + + my $col = $pos->{'ep_file_num'}; + if ($col == -1) { + $bits .= "0"; + } else { + $bits .= "1"; + $bits .= (qw(000 001 010 011 100 101 110 111))[$col]; + } + + return $board . pack('b*', $bits); +} + sub to_json_hash { my $pos = shift; my $json = { %$pos, fen => $pos->fen() }; @@ -128,7 +157,7 @@ sub num_pieces { # Returns a new Position object. sub make_move { - my ($pos, $from_row, $from_col, $to_row, $to_col, $promo) = @_; + my ($pos, $from_row, $from_col, $to_row, $to_col, $promo, $pretty_move) = @_; my $from_square = _pos_to_square($from_row, $from_col); my $to_square = _pos_to_square($to_row, $to_col); @@ -182,8 +211,12 @@ sub make_move { } $np->{'player_w'} = $pos->{'player_w'}; $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; + if (defined($pretty_move)) { + $np->{'last_move'} = $pretty_move; + } else { + 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;