Chess

 view release on metacpan or  search on metacpan

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


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

		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.294 second using v1.01-cache-2.11-cpan-e9199f4ba4c )