X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=Position.pm;h=371e179b8139d9541b85d874917cbc1255ee1768;hp=5d63ae2ff662d9abce22ba9bbe40a729ea7b8f8d;hb=aab426550a1da4daea35eb0b0691fe8bd7907348;hpb=8bb77e05c46c67ba4fe237f47d0e6fe52a57b694 diff --git a/Position.pm b/Position.pm index 5d63ae2..371e179 100644 --- a/Position.pm +++ b/Position.pm @@ -4,6 +4,7 @@ # use strict; use warnings; +use MIME::Base64; require 'Board.pm'; @@ -36,6 +37,8 @@ sub new { sub start_pos { my ($class, $white, $black) = @_; + $white = "base64:" . MIME::Base64::encode_base64($white); + $black = "base64:" . MIME::Base64::encode_base64($black); return $class->new("<12> rnbqkbnr pppppppp -------- -------- -------- -------- PPPPPPPP RNBQKBNR W -1 1 1 1 1 0 dummygamenum $white $black -2 dummytime dummyincrement 39 39 dummytime dummytime 1 none (0:00) none 0 0 0"); } @@ -103,7 +106,14 @@ sub fen { sub to_json_hash { my $pos = shift; - return { %$pos, board => undef, fen => $pos->fen() }; + my $json = { %$pos, board => undef, fen => $pos->fen() }; + if ($json->{'player_w'} =~ /^base64:(.*)$/) { + $json->{'player_w'} = MIME::Base64::decode_base64($1); + } + if ($json->{'player_b'} =~ /^base64:(.*)$/) { + $json->{'player_b'} = MIME::Base64::decode_base64($1); + } + return $json; } sub parse_pretty_move { @@ -167,7 +177,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; }