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


PHP Board::square_up_from方法代码示例

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


在下文中一共展示了Board::square_up_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_up_from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。