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


PHP Board::add_horz_distance方法代碼示例

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


在下文中一共展示了Board::add_horz_distance方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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();
     $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

示例3: 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

示例4: 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);
     $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,代碼行數:42,代碼來源:Queen.class.php


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