private function FindMovesToTile($nRank, $nFile) { $this->nCalls++; $Kings; $Knights; $Pawns; $Rooks; $Bishops; // Bitmaps for storing attacking pieces. $n64One = new BitBoard('0x1'); // Find the pieces a king/knight/rook/bishop could attack from this position. // Queens will show up in the rook and bishop bitmaps. $Kings = $this->FindTilesAttackedByKing($nRank, $nFile)->_AND(BitBoard::_OR_($this->n64BKing, $this->n64WKing)); $Bishops = $this->FindTilesAttackedByBishop($nRank, $nFile)->_AND(BitBoard::_OR_($this->n64BBishops, $this->n64WBishops)->_OR($this->n64WQueens)->_OR($this->n64BQueens)); $Rooks = $this->FindTilesAttackedByRook($nRank, $nFile)->_AND(BitBoard::_OR_($this->n64BRooks, $this->n64WRooks)->_OR($this->n64WQueens)->_OR($this->n64BQueens)); $Knights = $this->FindTilesAttackedByKnight($nRank, $nFile)->_AND(BitBoard::_OR_($this->n64WKnights, $this->n64BKnights)); $Pawns = new BitBoard(); // Pawns are handled differently. The pawn's move to bitmap is taken and ANDed with the tile // provided to the function so we know if the pawn can move to that tile. The pawn square is // usually one more/less than the rank, unless the rank is 3 or 4 in which case the starting // rank for the pawn may also be checked to see if the pawn can jump two tiles. if ($nRank > 0 && !$this->WPawnAttacks[($nRank - 1) * 8 + $nFile]->is_zero() && !$this->Tiles[$nRank * 8 + $nFile]->is_zero()) { if (!BitBoard::_AND_($this->n64WPawns, $this->Tiles[($nRank - 1) * 8 + $nFile])->is_zero()) { $Pawns = $this->Tiles[($nRank - 1) * 8 + $nFile]->duplicate(); } } if ($nRank == 3) { // Need to check if there is a blocking piece before this pawn can be added. if (!BitBoard::_AND_($this->n64WPawns, $this->Tiles[($nRank - 2) * 8 + $nFile])->is_zero() && BitBoard::_AND_($this->n64All, $this->Tiles[($nRank - 1) * 8 + $nFile])->is_zero()) { $Pawns->_OR($this->Tiles[($nRank - 2) * 8 + $nFile]); } } if ($nRank < 7 && !$this->BPawnAttacks[($nRank + 1) * 8 + $nFile]->is_zero() && !$this->Tiles[$nRank * 8 + $nFile]->is_zero()) { if (!BitBoard::_AND_($this->n64BPawns, $this->Tiles[($nRank + 1) * 8 + $nFile])->is_zero()) { $Pawns->_OR($this->Tiles[($nRank + 1) * 8 + $nFile]); } } if ($nRank == 4) { if (!BitBoard::_AND_($this->n64BPawns, $this->Tiles[($nRank + 2) * 8 + $nFile])->is_zero() && BitBoard::_AND_($this->n64All, $this->Tiles[($nRank + 1) * 8 + $nFile])->is_zero()) { $Pawns->_OR($this->Tiles[($nRank + 2) * 8 + $nFile]); } } //if ($this->PlayerTurn == 0) //{ // Pawns = FindTilesAttackedByPawn(nRank, nFile) & $this->n64BPawns; // // If not the bottom two ranks we can check if a pawn can move to this rank. // if (nRank > 1) // { // // See if there is a pawn one rank below. If so add it to the bitmap. // if (($this->n64WPawns & $this->Tiles[(nRank - 1) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank - 1) * 8 + nFile]; // // As there is no pawn one rank below, check if this is rank 3 which means // // a pawn two ranks below in rank 1 could move up to here as long as there // // is no piece in the way // else if (nRank == 3 && ($this->n64WPawns & $this->Tiles[(nRank - 2) * 8 + nFile]) > 0 && // ($this->n64All & $this->Tiles[(nRank - 2) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank - 2) * 8 + nFile]; // } // $this->PlayerTurn = 1; // Pawns |= FindTilesAttackedByPawn(nRank, nFile) & $this->n64WPawns; // if (nRank < 6) // { // if (($this->n64BPawns & $this->Tiles[(nRank + 1) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank + 1) * 8 + nFile]; // else if (nRank == 4 && ($this->n64BPawns & $this->Tiles[(nRank + 2) * 8 + nFile]) > 0 && // ($this->n64All & $this->Tiles[(nRank + 2) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank + 2) * 8 + nFile]; // } // $this->PlayerTurn = 0; //} //else if($this->PlayerTurn == 1) //{ // Pawns = FindTilesAttackedByPawn(nRank, nFile) & $this->n64WPawns; // if (nRank < 6) // { // if (($this->n64BPawns & $this->Tiles[(nRank + 1) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank + 1) * 8 + nFile]; // else if (nRank == 4 && ($this->n64BPawns & $this->Tiles[(nRank + 2) * 8 + nFile]) > 0 && // ($this->n64All & $this->Tiles[(nRank + 2) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank + 2) * 8 + nFile]; // } // $this->PlayerTurn = 0; // Pawns |= FindTilesAttackedByPawn(nRank, nFile) & $this->n64BPawns; // if (nRank > 1) // { // if (($this->n64WPawns & $this->Tiles[(nRank - 1) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank - 1) * 8 + nFile]; // else if (nRank == 3 && ($this->n64WPawns & $this->Tiles[(nRank - 2) * 8 + nFile]) > 0 && // ($this->n64All & $this->Tiles[(nRank - 2) * 8 + nFile]) > 0) // Pawns |= $this->Tiles[(nRank - 2) * 8 + nFile]; // } // $this->PlayerTurn = 1; //} // Combine all bitmaps and return. return $Kings->_OR($Bishops)->_OR($Rooks)->_OR($Knights)->_OR($Pawns); }