当前位置: 首页>>代码示例>>PHP>>正文


PHP Board::horz_distance方法代码示例

本文整理汇总了PHP中Board::horz_distance方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::horz_distance方法的具体用法?PHP Board::horz_distance怎么用?PHP Board::horz_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Board的用法示例。


在下文中一共展示了Board::horz_distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: reachable_squares

 function reachable_squares()
 {
     #Array of square where the piece can move to
     $squares = array();
     $csq = $this->get_current_square();
     $hdist = abs(Board::horz_distance("a1", $csq));
     $vdist = abs(Board::vert_distance("a1", $csq));
     $dist = $hdist > $vdist ? $vdist : $hdist;
     $sq = Board::add_horz_distance($csq, -$dist);
     $sq = Board::add_vert_distance($sq, -$dist);
     $squares = array_merge($squares, Board::squares_in_line($csq, $sq));
     $hdist = abs(Board::horz_distance("h1", $csq));
     $vdist = abs(Board::vert_distance("h1", $csq));
     $dist = $hdist > $vdist ? $vdist : $hdist;
     $sq = Board::add_horz_distance($csq, $dist);
     $sq = Board::add_vert_distance($sq, -$dist);
     $squares = array_merge($squares, Board::squares_in_line($csq, $sq));
     $hdist = abs(Board::horz_distance("a8", $csq));
     $vdist = abs(Board::vert_distance("a8", $csq));
     $dist = $hdist > $vdist ? $vdist : $hdist;
     $sq = Board::add_horz_distance($csq, -$dist);
     $sq = Board::add_vert_distance($sq, $dist);
     $squares = array_merge($squares, Board::squares_in_line($csq, $sq));
     $hdist = abs(Board::horz_distance("h8", $csq));
     $vdist = abs(Board::vert_distance("h8", $csq));
     $dist = $hdist > $vdist ? $vdist : $hdist;
     $sq = Board::add_horz_distance($csq, $dist);
     $sq = Board::add_vert_distance($sq, $dist);
     $squares = array_merge($squares, Board::squares_in_line($csq, $sq));
     #Removes current position square
     $squares = preg_grep("/^{$csq}\$/", $squares, PREG_GREP_INVERT);
     return $squares;
 }
开发者ID:iamdual,项目名称:phpcheckmate,代码行数:33,代码来源:Bishop.class.php

示例2: reachable_squares

 function reachable_squares()
 {
     #Array of square where the piece can move to
     $squares = array();
     $csq = $this->get_current_square();
     $x = Board::horz_distance("a4", $csq);
     $y = Board::vert_distance("d1", $csq);
     $row_start = 'a' . ($y + 1);
     $row_end = 'h' . ($y + 1);
     $col_start = chr(ord('a') + $x) . '1';
     $col_end = chr(ord('a') + $x) . '8';
     $row = Board::squares_in_line($row_start, $row_end);
     $col = Board::squares_in_line($col_start, $col_end);
     $squares = array_merge($squares, $row, $col);
     #Removes current position square
     $squares = preg_grep("/^{$csq}\$/", $squares, PREG_GREP_INVERT);
     return $squares;
 }
开发者ID:iamdual,项目名称:phpcheckmate,代码行数:18,代码来源:Rook.class.php

示例3: is_move_legal

 /**
  * Takes two parameters containing the name of the square to move 
  * from and the name of the square to move to. They should be validated 
  * with "square_is_valid()" in Board prior to calling. Returns true 
  * if the provided move is legal within the context of the current game.
  * 
  * @param string $sq1 current position of the piece
  * @param string $sq2 destination of the piece
  * 
  * @return bool true if the move is legal or false otherwise
  */
 public function is_move_legal($sq1, $sq2)
 {
     #check squares are on the board
     if (Board::square_is_valid($sq1) == false) {
         return false;
     }
     if (Board::square_is_valid($sq2) == false) {
         return false;
     }
     $player1 = $this->players[0];
     $player2 = $this->players[1];
     $board = $this->board;
     $piece = $board->get_piece_at($sq1);
     #trying to move invisible piece
     if ($piece == NULL) {
         return -1;
     }
     $player = $piece->get_player();
     $movelist = $this->movelist;
     $last_moved = $movelist->get_last_moved();
     #check whose turn is
     if ($last_moved != NULL && $last_moved == $player || $last_moved == NULL && $player != $player1) {
         $this->message = "Not your turn";
         return false;
     }
     #square not reacheable for this piece
     if ($piece->can_reach($sq2) == false) {
         return false;
     }
     #if capturing anything
     $capture = $board->get_piece_at($sq2);
     if ($capture) {
         if ($capture->get_player() == $player) {
             $this->message = "You can't capture your own piece";
             return false;
         }
         #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;
//.........这里部分代码省略.........
开发者ID:iamdual,项目名称:phpcheckmate,代码行数:101,代码来源:Game.class.php


注:本文中的Board::horz_distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。