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


PHP Board::square_down_from方法代碼示例

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


在下文中一共展示了Board::square_down_from方法的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;
 }
開發者ID:iamdual,項目名稱:phpcheckmate,代碼行數:51,代碼來源:Knight.class.php

示例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;
 }
開發者ID:iamdual,項目名稱:phpcheckmate,代碼行數:47,代碼來源:King.class.php

示例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;
 }
開發者ID:iamdual,項目名稱:phpcheckmate,代碼行數:44,代碼來源:Pawn.class.php

示例4: take_back_move

 /**
  * Returns MoveListEntry representing the 
  * last move made, and sets the state of the game to what it was prior to the 
  * returned move being made.
  * 
  * @return MoveListEntry the last MoveListEntry object of the move that has been taken back
  */
 public function take_back_move()
 {
     $movelist = $this->movelist;
     $board = $this->board;
     $curr_player = $movelist->get_last_moved();
     $player1 = $this->players[0];
     $move = $movelist->delete_move();
     #There is a existing last move
     if ($move) {
         $movenum = $move->get_move_num();
         $piece = $move->get_piece();
         $player = $piece->get_player();
         $ssq = $move->get_start_square();
         $dsq = $move->get_dest_square();
         #If last move was a promotion
         if ($move->is_promotion()) {
             //delete the prometed piece
             $hash = $move->get_promoted_hash();
             unset($this->pieces[$piece->get_player()][$hash]);
         }
         #If last move was a capture
         if ($move->is_capture()) {
             $capture = $this->captures[$player][$movenum];
             if ($move->is_en_passant()) {
                 if ($player == $player1) {
                     $dsq = Board::square_down_from($dsq);
                 } else {
                     $dsq = Board::square_up_from($dsq);
                 }
             }
             $board->set_piece_at($dsq, $capture);
             $capture->set_current_square($dsq);
             $capture->set_captured(0);
             $board->set_piece_at($ssq, $piece);
             $piece->set_current_square($ssq);
             if ($piece->_firstmoved() == $movenum) {
                 $piece->set_moved(0);
             }
         } elseif ($move->is_short_castle()) {
             $king_sq = $player == $player1 ? "e1" : "e8";
             $rook_sq = $player == $player1 ? "h1" : "h8";
             $king_curr_sq = $player == $player1 ? "g1" : "g8";
             $rook_curr_sq = $player == $player1 ? "f1" : "f8";
             $rook = $board->get_piece_at($rook_curr_sq);
             $board->set_piece_at($king_curr_sq, NULL);
             $board->set_piece_at($rook_curr_sq, NULL);
             $board->set_piece_at($king_sq, $piece);
             $board->set_piece_at($rook_sq, $rook);
             $rook->set_current_square($rook_sq);
             $piece->set_current_square($king_sq);
             $rook->set_moved(0);
             $piece->set_moved(0);
         } elseif ($move->is_long_castle()) {
             $king_sq = $player == $player1 ? "e1" : "e8";
             $rook_sq = $player == $player1 ? "a1" : "a8";
             $king_curr_sq = $player == $player1 ? "c1" : "c8";
             $rook_curr_sq = $player == $player1 ? "d1" : "d8";
             $rook = $board->get_piece_at($rook_curr_sq);
             $board->set_piece_at($king_curr_sq, NULL);
             $board->set_piece_at($rook_curr_sq, NULL);
             $board->set_piece_at($king_sq, $piece);
             $board->set_piece_at($rook_sq, $rook);
             $rook->set_current_square($rook_sq);
             $piece->set_current_square($king_sq);
             $rook->set_moved(0);
             $piece->set_moved(0);
         } else {
             $board->set_piece_at($dsq, NULL);
             $board->set_piece_at($ssq, $piece);
             $piece->set_current_square($ssq);
             if ($piece->_firstmoved() == $movenum) {
                 $piece->set_moved(0);
             }
         }
         #delete last
         unset($this->player_has_moves[$player][$movenum]);
     }
     return $move;
 }
開發者ID:iamdual,項目名稱:phpcheckmate,代碼行數:86,代碼來源:Game.class.php


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