Beispiel #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 && !kingKillable("k,1,1," + $aboard->toString()) && !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 && !kingKillable("k,1,1," + $aboard->toString()) && !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 && !kingKillable("k,1,1," + $aboard->toString()) && !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 && !kingKillable("k,1,1," + $aboard->toString()) && !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;
 }
Beispiel #2
0
 public static function rightCastleThroughCheck($input)
 {
     $alter = new ChessBoard();
     $alter->copy($input);
     $alter->changeTurn();
     if ($input->whiteTurn()) {
         $alter->set(5, 1, -1);
         $alter->set(6, 1, ChessBoard::$WHITEKING);
     } else {
         $alter->set(5, 8, -1);
         $alter->set(6, 8, ChessBoard::$BLACKKING);
     }
     return self::kingKillable("K,1,1," + $alter->toString());
 }