本文整理汇总了PHP中Board::squares_in_line方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::squares_in_line方法的具体用法?PHP Board::squares_in_line怎么用?PHP Board::squares_in_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board::squares_in_line方法的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;
}
示例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;
}
示例3: __construct
/**
* Takes two optional parameters containing optional names for the players.
* If none are provided, the player names 'white' and 'black' are used.
* Creates a new Board and places 16 Pieces per player and
* initializes an empty MoveList.
* @param string $p1 Player1's name
* @param string $p2 Player2's name
* @return Game
*/
function __construct($p1 = '', $p2 = '')
{
#player names
$player1 = $p1 ? $p1 : 'white';
$player2 = $p2 ? $p2 : 'black';
#create the board content
$this->board = new Board();
$this->pieces = array($player1 => array(), $player2 => array());
$this->captures = array($player1 => array(), $player2 => array());
$this->player_has_moves = array($player1 => array(1 => 1), $player2 => array(1 => 1));
$this->movelist = new MoveList($player1, $player2);
$this->players = array($player1, $player2);
#Add Rooks, Knights, Bishops and Queens to the board
$this->add_pieces('Rook', array('a1', 'h1'), $player1);
$this->add_pieces('Rook', array('a8', 'h8'), $player2);
$this->add_pieces('Knight', array('b1', 'g1'), $player1);
$this->add_pieces('Knight', array('b8', 'g8'), $player2);
$this->add_pieces('Bishop', array('c1', 'f1'), $player1);
$this->add_pieces('Bishop', array('c8', 'f8'), $player2);
$this->add_pieces('Queen', array('d1'), $player1);
$this->add_pieces('Queen', array('d8'), $player2);
#add kings to the board
$hash = $this->add_pieces('King', array('e1'), $player1);
$this->kings[] = $this->pieces[$player1][$hash];
$hash = $this->add_pieces('King', array('e8'), $player2);
$this->kings[] = $this->pieces[$player2][$hash];
#add pawns to the board
$pawn_row = Board::squares_in_line("a2", "h2");
$this->add_pieces('Pawn', $pawn_row, $player1);
$pawn_row = Board::squares_in_line("a7", "h7");
$this->add_pieces('Pawn', $pawn_row, $player2);
return $this;
}