Chess

 view release on metacpan or  search on metacpan

lib/Chess/Board.pm  view on Meta::CPAN

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Takes no arguments. Returns a blessed Chess::Board object reference which is
identical to the caller object. However, it is a I<deep copy> which allows
the clone()'d object to be manipulated separately of the caller object.
 
=item line_is_open()
 
Takes two scalar arguments, valid squares defining the endpoints of a line
on the Chess::Board. Returns true if there are no pieces on either of the
endpoints, or on any of the intervening squares. Returns false if the line
is blocked by one or more pieces, and C<undef> if the two squares do not
define endpoints of a line. In the case where both squares are equal, will
return true if the square is empty and false otherwise.
 
=item get_piece_at()
 
Takes a single scalar argument containing the square to retrieve the piece
from. Returns a scalar representing the piece on that square, or C<undef> if
there is none. Returns C<undef> and prints a warning to STDERR (See
L</"DIAGNOSTICS">) if the provided square is not valid.

lib/Chess/Game.pm  view on Meta::CPAN

626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
            return 0 unless (_is_valid_long_castle($obj_data, $piece, $sq1, $sq2));
            $valid_castle = MOVE_CASTLE_LONG;
        }
    }
}
elsif (!$piece->isa('Chess::Piece::Knight')) {
    my $board_c = $board->clone();
    $board_c->set_piece_at($sq1, undef);
    $board_c->set_piece_at($sq2, undef);
    unless ($board_c->line_is_open($sq1, $sq2)) {
        $obj_data->{message} = "Line '$sq1' - '$sq2' is blocked";
        return 0;
    }
}
if (!$valid_castle) {
    $clone->make_move($sq1, $sq2, 0);
    _mark_threatened_kings($r_clone);
    unless (!$king->threatened()) {
        $obj_data->{message} = "Move leaves your king in check";
        return 0;
    }



( run in 0.253 second using v1.01-cache-2.11-cpan-e9199f4ba4c )