Exemplo n.º 1
0
 /**
  * Checks whether the given piece follow a long castle move
  * 
  * @param Piece $piece the piece to check
  * @param string $sq1 current position of the piece
  * @param string $sq2 destination of the piece
  * 
  * @return bool returns true if 'long castle' is valid or false otherwise
  */
 private function _is_valid_long_castle($piece, $sq1, $sq2)
 {
     $player1 = $this->players[0];
     $player2 = $this->players[1];
     $player = $piece->get_player();
     $board = $this->board;
     $tsq = $player == $player1 ? "c1" : "c8";
     if ($sq2 != $tsq) {
         return false;
     }
     if ($piece->moved()) {
         $this->message = ucfirst($player) . "'s king has already moved";
         return false;
     }
     $rook == NULL;
     if ($player == $player1) {
         $rook = $board->get_piece_at("a1");
     } else {
         $rook = $board->get_piece_at("a8");
     }
     if ($rook == false || $rook->moved()) {
         $this->message = ucfirst($player) . "'s queenside rook has already moved";
         return false;
     }
     $rook_sq = $player == $player1 ? "a1" : "a8";
     $king_sq = $player == $player1 ? "e1" : "e8";
     $board_c = clone $board;
     $board_c->set_piece_at($king_sq, NULL);
     $board_c->set_piece_at($rook_sq, NULL);
     if ($board_c->line_is_open($king_sq, $rook_sq) == false) {
         $this->message = "There are pieces between " . ucfirst($player) . "'s king and rook";
         return false;
     }
     return true;
 }