Subject: | fixed bug in Chess::Game |
Date: | Sun, 29 Jul 2007 17:38:39 +0400 |
To: | bug-Chess [...] rt.cpan.org |
From: | Семичёв Сергей <vertolet666 [...] yandex.ru> |
I solved the bug as I reported before.
You may see this report here http://rt.cpan.org/Ticket/Display.html?id=28538
The question is sub 'sub _player_has_moves' in Game.pm doesn't take into account legal moves of King.
I have rewrited it like this:
------------------------------------------
sub _player_has_moves {
my ($self, $player) = @_;
my $obj_data = _get_game($$self);
my $movelist = $obj_data->{movelist};
my $movenum = $movelist->get_move_num;
my $king;
if (exists($obj_data->{_player_has_moves}{$player}{$movenum})) {
return $obj_data->{_player_has_moves}{$player}{$movenum};
}
foreach my $piece (@{$obj_data->{pieces}{$player}}) {
$king = ($piece->isa('Chess::Piece::King')) ? $piece : undef;
if (defined $king) {
my @rsqs = $king->reachable_squares();
my $csq = $king->get_current_square();
foreach my $sq (@rsqs) {
if ($self->is_move_legal($csq, $sq)) {
$obj_data->{_player_has_moves}{$player}{$movenum} = 1;
return 1;
}
}
};
next if ($piece->isa('Chess::Piece::King') or $piece->captured());
my @rsqs = $piece->reachable_squares();
my $csq = $piece->get_current_square();
foreach my $sq (@rsqs) {
if ($self->is_move_legal($csq, $sq)) {
$obj_data->{_player_has_moves}{$player}{$movenum} = 1;
return 1;
}
}
};
$obj_data->{_player_has_moves}{$player}{$movenum} = 0;
return 0;
}
------------------------------------------
Now this it works correctly.
Best regards, Semichev Sergei.