Exemple #1
0
 public function generatePreList()
 {
     $temp = new ChessBoard();
     $aboard = new ChessBoard();
     $moves = array();
     $output = array();
     $moves[] = array(1, -1);
     $moves[] = array(1, 0);
     $moves[] = array(1, 1);
     $moves[] = array(-1, 1);
     $moves[] = array(-1, -1);
     $moves[] = array(-1, 0);
     $moves[] = array(0, 1);
     $moves[] = array(0, -1);
     foreach ($moves as $move) {
         $output = array_merge($output, $this->addBoard($this->x, $this->y, $move));
     }
     //the rest is castling conditions
     if ($this->typecode == ChessBoard::$WHITEKING) {
         //white king castling to the left
         if ($this->x == 5 && $this->y == 1 && $this->board->get(4, 1) == -1 && $this->board->get(3, 1) == -1 && $this->board->get(2, 1) == -1 && $this->board->get(1, 1) == ChessBoard::$WHITEROOK && !($this->board->castleData() & 64) && !($this->board->castleData() & 32)) {
             $aboard->copy($this->board);
             $aboard->changeTurn();
             if ($this->recurse && !ChessBoard::kingKillable("k,1,1," + $aboard->toString()) && !ChessBoard::leftCastleThroughCheck($this->board)) {
                 $temp->copy($this->board);
                 $temp->set(1, 1, -1);
                 $temp->set(3, 1, ChessBoard::$WHITEKING);
                 $temp->set(4, 1, ChessBoard::$WHITEROOK);
                 $temp->set(5, 1, -1);
                 $temp->setLastMove(5, 1, 3, 1);
                 $temp->changeTurn();
                 $temp->checkKingRookHome();
                 $output[] = $temp->toString();
             }
         }
         // white king castling to the right
         if ($this->x == 5 && $this->y == 1 && $this->board->get(6, 1) == -1 && $this->board->get(7, 1) == -1 && $this->board->get(8, 1) == ChessBoard::$WHITEROOK && !($this->board->castleData() & 64) && !($this->board->castleData() & 16)) {
             $aboard->copy($this->board);
             $aboard->changeTurn();
             if ($this->recurse && !ChessBoard::kingKillable("k,1,1," + $aboard->toString()) && !ChessBoard::rightCastleThroughCheck($this->board)) {
                 $temp->copy($this->board);
                 $temp->set(8, 1, -1);
                 $temp->set(7, 1, ChessBoard::$WHITEKING);
                 $temp->set(6, 1, ChessBoard::$WHITEROOK);
                 $temp->set(5, 1, -1);
                 $temp->setLastMove(5, 1, 7, 1);
                 $temp->changeTurn();
                 $temp->checkKingRookHome();
                 $output[] = $temp->toString();
             }
         }
     }
     if ($this->typecode == ChessBoard::$BLACKKING) {
         // black king castling to the left
         if ($this->x == 5 && $this->y == 8 && $this->board->get(4, 8) == -1 && $this->board->get(3, 8) == -1 && $this->board->get(2, 8) == -1 && $this->board->get(1, 8) == ChessBoard::$BLACKROOK && !($this->board->castleData() & 4) && !($this->board->castleData() & 2)) {
             $aboard->copy($this->board);
             $aboard->changeTurn();
             if ($this->recurse && !ChessBoard::kingKillable("k,1,1," + $aboard->toString()) && !ChessBoard::leftCastleThroughCheck($this->board)) {
                 $temp->copy($this->board);
                 $temp->set(1, 8, -1);
                 $temp->set(3, 8, ChessBoard::$BLACKKING);
                 $temp->set(4, 8, ChessBoard::$BLACKROOK);
                 $temp->set(5, 8, -1);
                 $temp->setLastMove(5, 8, 3, 8);
                 $temp->changeTurn();
                 $temp->checkKingRookHome();
                 $output[] = $temp->toString();
             }
         }
         // black king castling to the right
         if ($this->x == 5 && $this->y == 8 && $this->board->get(6, 8) == -1 && $this->board->get(7, 8) == -1 && $this->board->get(8, 8) == ChessBoard::$BLACKROOK && !($this->board->castleData() & 4) && !($this->board->castleData() & 1)) {
             $aboard->copy($this->board);
             $aboard->changeTurn();
             if ($this->recurse && !ChessBoard::kingKillable("k,1,1," + $aboard->toString()) && !ChessBoard::rightCastleThroughCheck($this->board)) {
                 $temp->copy($this->board);
                 $temp->set(8, 8, -1);
                 $temp->set(7, 8, ChessBoard::$BLACKKING);
                 $temp->set(6, 8, ChessBoard::$BLACKROOK);
                 $temp->set(5, 8, -1);
                 $temp->setLastMove(5, 8, 7, 8);
                 $temp->changeTurn();
                 $temp->checkKingRookHome();
                 $output[] = $temp->toString();
             }
         }
     }
     return $output;
 }