本文整理汇总了PHP中Board::square_left_of方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::square_left_of方法的具体用法?PHP Board::square_left_of怎么用?PHP Board::square_left_of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board::square_left_of方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reachable_squares
function reachable_squares()
{
#Array of square where the piece can move to
$squares = array();
$csq = $this->get_current_square();
$tsq = Board::add_vert_distance($csq, 2);
if ($tsq) {
$sq = Board::square_right_of($tsq);
if ($sq) {
$squares[] = $sq;
}
$sq = Board::square_left_of($tsq);
if ($sq) {
$squares[] = $sq;
}
}
$tsq = Board::add_vert_distance($csq, -2);
if ($tsq) {
$sq = Board::square_right_of($tsq);
if ($sq) {
$squares[] = $sq;
}
$sq = Board::square_left_of($tsq);
if ($sq) {
$squares[] = $sq;
}
}
$tsq = Board::add_horz_distance($csq, 2);
if ($tsq) {
$sq = Board::square_up_from($tsq);
if ($sq) {
$squares[] = $sq;
}
$sq = Board::square_down_from($tsq);
if ($sq) {
$squares[] = $sq;
}
}
$tsq = Board::add_horz_distance($csq, -2);
if ($tsq) {
$sq = Board::square_up_from($tsq);
if ($sq) {
$squares[] = $sq;
}
$sq = Board::square_down_from($tsq);
if ($sq) {
$squares[] = $sq;
}
}
return $squares;
}
示例2: reachable_squares
function reachable_squares()
{
#Array of square where the piece can move to
$squares = array();
$csq = $this->get_current_square();
$sq1 = Board::square_left_of($csq);
if ($sq1) {
$squares[] = $sq1;
$sq2 = Board::square_up_from($sq1);
if (defined($sq2)) {
$squares[] = $sq2;
}
$sq2 = Board::square_down_from($sq1);
if (defined($sq2)) {
$squares[] = $sq2;
}
}
$sq1 = Board::square_right_of($csq);
if ($sq1) {
$squares[] = $sq1;
$sq2 = Board::square_up_from($sq1);
if ($sq2) {
$squares[] = $sq2;
}
$sq2 = Board::square_down_from($sq1);
if ($sq2) {
$squares[] = $sq2;
}
}
$sq1 = Board::square_up_from($csq);
if ($sq1) {
$squares[] = $sq1;
}
$sq1 = Board::square_down_from($csq);
if ($sq1) {
$squares[] = $sq1;
}
$sq1 = Board::add_horz_distance($csq, 2);
if ($sq1 && !$this->moved()) {
$squares[] = $sq1;
}
$sq1 = Board::add_horz_distance($csq, -2);
if ($sq1 && !$this->moved()) {
$squares[] = $sq1;
}
return $squares;
}
示例3: reachable_squares
function reachable_squares()
{
#Array of square where the piece can move to
$squares = array();
$color = $this->get_player();
$csq = $this->get_current_square();
if ($color == 'white') {
if ($csq) {
$tsq1 = Board::square_up_from($csq);
}
} else {
if ($csq) {
$tsq1 = Board::square_down_from($csq);
}
}
if (isset($tsq1)) {
$squares[] = $tsq1;
}
if ($color == 'white') {
if ($tsq1) {
$tsq2 = Board::square_up_from($tsq1);
}
} else {
if ($tsq1) {
$tsq2 = Board::square_down_from($tsq1);
}
}
if (!$this->moved() and $tsq2) {
$squares[] = $tsq2;
}
if ($tsq1) {
$tsq2 = Board::square_left_of($tsq1);
}
if ($tsq2) {
$squares[] = $tsq2;
}
if ($tsq1) {
$tsq2 = Board::square_right_of($tsq1);
}
if ($tsq2) {
$squares[] = $tsq2;
}
return $squares;
}
示例4: is_move_legal
//.........这里部分代码省略.........
}
#Pawn try to capture
if ($piece instanceof Pawn) {
if (abs(Board::horz_distance($sq1, $sq2)) != 1) {
$this->message = "Pawns may only capture diagonally";
return false;
}
} elseif ($piece instanceof King) {
if (abs(Board::horz_distance($sq1, $sq2)) >= 2) {
$this->message = "You can't capture while castling";
return false;
}
}
} else {
#Check "en passant" capture
if ($piece instanceof Pawn) {
$ml = $piece->movelist;
if (Board::horz_distance($sq1, $sq2) != 0 && $this->_is_valid_en_passant($piece, $sq1, $sq2) == false) {
$this->message = "Pawns must capture on a diagonal move";
return false;
}
}
}
$valid_castle = 0;
$clone = clone $this;
$king = $clone->kings[$player == $player1 ? 0 : 1];
#Piece is a King
if ($piece instanceof King) {
$hdist = Board::horz_distance($sq1, $sq2);
if (abs($hdist) == 2) {
self::_mark_threatened_kings($clone);
if ($king->threatened()) {
$this->message = "Can't castle out of check";
return false;
}
if ($hdist > 0) {
if ($this->_is_valid_short_castle($piece, $sq1, $sq2) == false) {
return false;
}
$valid_castle = self::__MOVE_CASTLE_SHORT__;
} else {
if ($this->_is_valid_long_castle($piece, $sq1, $sq2) == false) {
return false;
}
$valid_castle = self::__MOVE_CASTLE_LONG__;
}
}
} elseif (!$piece instanceof King) {
$board_c = clone $board;
$board_c->set_piece_at($sq1, NULL);
$board_c->set_piece_at($sq2, NULL);
if ($board_c->line_is_open($sq1, $sq2) == false) {
$this->message = "Line '{$sq1}' - '{$sq2}' is blocked";
return false;
}
}
#move is not a castle
if (!$valid_castle) {
$clone->make_move($sq1, $sq2, false);
self::_mark_threatened_kings($clone);
if ($king->threatened()) {
$this->message = "Move leaves your king in check";
return false;
}
} else {
#Short castle move
if ($valid_castle == self::__MOVE_CASTLE_SHORT__) {
$tsq = Board::square_right_of($sq1);
$clone->make_move($sq1, $tsq, 0);
self::_mark_threatened_kings($clone);
if ($king->threatened()) {
$this->message = "Can't castle through check";
return false;
}
$clone->make_move($tsq, $sq2, 0);
self::_mark_threatened_kings($clone);
if ($king->threatened()) {
$this->message = "Move leaves your king in check";
return false;
}
} else {
$tsq = Board::square_left_of($sq1);
$clone->make_move($sq1, $tsq, 0);
self::_mark_threatened_kings($clone);
if ($king->threatened()) {
$this->message = "Can't castle through check";
return false;
}
$clone->make_move($tsq, $sq2, 0);
self::_mark_threatened_kings($clone);
if ($king->threatened()) {
die;
$this->message = "Move leaves your king in check";
return false;
}
}
}
$this->message = '';
return true;
}