當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Board::square_is_valid方法代碼示例

本文整理匯總了PHP中Board::square_is_valid方法的典型用法代碼示例。如果您正苦於以下問題:PHP Board::square_is_valid方法的具體用法?PHP Board::square_is_valid怎麽用?PHP Board::square_is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Board的用法示例。


在下文中一共展示了Board::square_is_valid方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _get_square_coords

 /**
  * Gets the coordinates of a square position
  * 
  * @param string $sq square position on the board
  * @return array x,y coordinates
  */
 static function _get_square_coords($sq)
 {
     #If $sq is not a valid square
     if (Board::square_is_valid($sq) == false) {
         return NULL;
     }
     $x = ord(strtolower(substr($sq, 0, 1))) - ord('a');
     $y = substr($sq, 1, 1) - 1;
     return array($x, $y);
 }
開發者ID:iamdual,項目名稱:phpcheckmate,代碼行數:16,代碼來源:Board.class.php

示例2: make_move

 /**
  * 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 before calling. Optionally takes a 
  * third parameter, which can be set to zero to indicate that no legality 
  * checking should be done. In this case, flags indicating 'en passant' pawn 
  * captures or castling will not be set! Only by entirely validating the move 
  * do these flags have any meaning. The default is to validate every move. 
  * 
  * @param string $sq1 current position of the piece
  * @param string $sq2 destination of the piece
  * @param bool $validate whether to validate the move 
  * 
  * @return MoveListEntry|NULL a MoveListEntry representing the move just made or NULL
  * if any errors occur and the move was not considered  
  */
 public function make_move($sq1, $sq2, $validate = true)
 {
     $move = NULL;
     #Invalid square
     if (Board::square_is_valid($sq1) == false) {
         return NULL;
     }
     if (Board::square_is_valid($sq2) == false) {
         return NULL;
     }
     if ($validate) {
         if ($this->is_move_legal($sq1, $sq2) == false) {
             return NULL;
         }
     }
     $player1 = $this->players[0];
     $player2 = $this->players[1];
     $board = $this->board;
     $piece = $board->get_piece_at($sq1);
     $player = $piece->get_player();
     #if no piece at sq1
     if ($piece == NULL) {
         return NULL;
     }
     $movelist = $this->movelist;
     $capture = $board->get_piece_at($sq2);
     $flags = 0x0;
     if ($validate && $piece instanceof Pawn) {
         if ($player == $player1) {
             if (Board::vert_distance("d8", $sq2) == 0) {
                 $flags = $flags | self::__MOVE_PROMOTE__;
             }
             //Bitwise Or
         } else {
             if (Board::vert_distance("d1", $sq2) == 0) {
                 $flags = $flags | self::__MOVE_PROMOTE__;
             }
             //Bitwise Or
         }
     }
     if ($capture) {
         $flags = $flags | self::__MOVE_CAPTURE__;
         //Bitwise Or
         $capture->set_captured(1);
         $board->set_piece_at($sq1, NULL);
         $board->set_piece_at($sq2, $piece);
         $piece->set_current_square($sq2);
         $piece->set_moved(1);
         $move = $movelist->add_move($piece, $sq1, $sq2, $flags);
         $movenum = $move->get_move_num();
         $this->captures[$player][$movenum] = $capture;
     } else {
         if ($validate && $piece instanceof Pawn && $this->_is_valid_en_passant($piece, $sq1, $sq2)) {
             $last_moved = $movelist->get_last_moved();
             $move = $movelist->get_move($movelist->get_move_num(), $last_moved);
             $capture = $move->get_piece();
             $flags = $flags | self::__MOVE_CAPTURE__;
             $flags = $flags | self::__MOVE_EN_PASSANT__;
             $capture->set_captured(1);
             $board->set_piece_at($sq1, NULL);
             $board->set_piece_at($sq2, $piece);
             $piece->set_current_square($sq2);
             $move = $movelist->add_move($piece, $sq1, $sq2, $flags);
             $this->analyzed = 0;
             $movenum = $move->get_move_num();
             $piece->_set_firstmoved($movenum);
             $this->captures[$player][$movenum] = $capture;
         } else {
             if ($validate && $piece instanceof King) {
                 if ($this->_is_valid_short_castle($piece, $sq1, $sq2)) {
                     $flags = $flags | self::__MOVE_CASTLE_SHORT__;
                 }
                 if ($this->_is_valid_long_castle($piece, $sq1, $sq2)) {
                     $flags = $flags | self::__MOVE_CASTLE_LONG__;
                 }
             }
             if ($flags & self::__MOVE_CASTLE_SHORT__ || $flags & self::__MOVE_CASTLE_LONG__) {
                 $rook_sq = $king_sq = $rook_sq_new = $king_sq_new = NULL;
                 $rook = $king = NULL;
                 if ($player == $player1) {
                     $rook_sq = $flags & self::__MOVE_CASTLE_SHORT__ ? "h1" : "a1";
                     $rook_sq_new = $flags & self::__MOVE_CASTLE_SHORT__ ? "f1" : "d1";
                     $king_sq = "e1";
                     $king_sq_new = $flags & self::__MOVE_CASTLE_SHORT__ ? "g1" : "c1";
//.........這裏部分代碼省略.........
開發者ID:iamdual,項目名稱:phpcheckmate,代碼行數:101,代碼來源:Game.class.php


注:本文中的Board::square_is_valid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。