private function CanBlockCheckingPiece($nKingTile, $nAttackTile) { $this->nCalls++; // Get all tiles between the attacking piece and the king. Try to block one after the // other and test if making such a move gets us out of check. If a good move is found // return. $tiles = $this->GetTilesBetweenTwoTiles($this->floor[$nAttackTile], $nAttackTile % 8, $this->floor[$nKingTile], $nKingTile % 8); if (count($tiles) == 0) { return false; } foreach ($tiles as $nTile) { // See if any of the current player's pieces (except for the king) can move to this tile. if ($this->PlayerTurn == 0) { //bitmap = FindAttacksToTile(nTile / 8, nTile % 8) & ($this->n64WAll ^ $this->n64WKing); $bitmap = $this->FindMovesToTile($this->floor[$nTile], $nTile % 8)->_AND(BitBoard::_XOR_($this->n64WAll, $this->n64WKing)); } else { //bitmap = FindAttacksToTile(nTile / 8, nTile % 8) & ($this->n64BAll ^ $this->n64BKing); $bitmap = $this->FindMovesToTile($this->floor[$nTile], $nTile % 8)->_AND(BitBoard::_XOR_($this->n64BAll, $this->n64BKing)); } $tiles2 = $this->ChessUtils->GetTilesFromBitmap($bitmap); foreach ($tiles2 as $nSourceTile) { // Move the piece and if the king is no longer in check then all is good. $this->Board_MovePiece($nSourceTile % 8, $this->floor[$nSourceTile], $nTile % 8, $this->floor[$nTile]); if ($this->PlayerTurn == 0) { $bitmap = $this->FindAttacksToTile($this->floor[$nKingTile], $nKingTile % 8)->_AND($this->n64BAll); } else { $bitmap = $this->FindAttacksToTile($this->floor[$nKingTile], $nKingTile % 8)->_AND($this->n64WAll); } if ($bitmap->is_zero()) { // Undo temp move. $this->Board_MovePiece_($nTile % 8, $this->floor[$nTile], $nSourceTile % 8, $this->floor[$nSourceTile], $this->Board[$this->floor[$nSourceTile]][$nSourceTile % 8]); return true; } // Undo temp move. $this->Board_MovePiece_($nTile % 8, $this->floor[$nTile], $nSourceTile % 8, $this->floor[$nSourceTile], $this->Board[$this->floor[$nSourceTile]][$nSourceTile % 8]); } } return false; }