X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitbase.cpp;h=36e93eead78eb6f602d5807e6a44513fa0840b27;hp=80db0a41fa31bbfcbc800effee0b2ecd3cb5b544;hb=c97104e8540b72ee2c6c9c13d3773d2c0f9ec32f;hpb=bb751d6c890f5c50c642366d601740366cfae8d0;ds=sidebyside diff --git a/src/bitbase.cpp b/src/bitbase.cpp index 80db0a41..36e93eea 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -1,17 +1,18 @@ /* - Glaurung, a UCI chess playing engine. - Copyright (C) 2004-2008 Tord Romstad + Stockfish, a UCI chess playing engine derived from Glaurung 2.1 + Copyright (C) 2004-2008 Tord Romstad (Glaurung author) + Copyright (C) 2008 Marco Costalba - Glaurung is free software: you can redistribute it and/or modify + Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - - Glaurung is distributed in the hope that it will be useful, + + Stockfish is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -52,11 +53,11 @@ namespace { Bitboard wk_attacks() const; Bitboard bk_attacks() const; Bitboard pawn_attacks() const; - + Square whiteKingSquare, blackKingSquare, pawnSquare; Color sideToMove; }; - + Result *Bitbase; const int IndexMax = 2*24*64*64; @@ -68,7 +69,7 @@ namespace { Result classify_btm(const KPKPosition &p); int compute_index(Square wksq, Square bksq, Square psq, Color stm); int compress_result(Result r); - + } @@ -112,7 +113,7 @@ namespace { return compute_index(whiteKingSquare, blackKingSquare, pawnSquare, sideToMove); } - + bool KPKPosition::is_legal() const { if(whiteKingSquare == pawnSquare || whiteKingSquare == blackKingSquare || @@ -136,7 +137,7 @@ namespace { if(sideToMove == BLACK) { Bitboard wka = this->wk_attacks(); Bitboard bka = this->bk_attacks(); - + // Case 1: Stalemate if((bka & ~(wka | this->pawn_attacks())) == EmptyBoardBB) return true; @@ -165,7 +166,7 @@ namespace { (square_distance(blackKingSquare, pawnSquare+DELTA_N) > 1 || bit_is_set(this->wk_attacks(), pawnSquare+DELTA_N)); } - + Bitboard KPKPosition::wk_attacks() const { return StepAttackBB[WK][whiteKingSquare]; @@ -203,7 +204,7 @@ namespace { bool next_iteration() { KPKPosition p; int previousUnknownCount = UnknownCount; - + for(int i = 0; i < IndexMax; i++) if(Bitbase[i] == RESULT_UNKNOWN) { p.from_index(i); @@ -230,7 +231,7 @@ namespace { bool unknownFound = false; Bitboard b; Square s; - + // King moves b = p.wk_attacks(); while(b) { @@ -259,14 +260,14 @@ namespace { BLACK)]) { case RESULT_LOSS: return RESULT_WIN; - + case RESULT_UNKNOWN: unknownFound = true; break; - + case RESULT_DRAW: case RESULT_INVALID: break; - + default: assert(false); } @@ -278,20 +279,20 @@ namespace { BLACK)]) { case RESULT_LOSS: return RESULT_WIN; - + case RESULT_UNKNOWN: unknownFound = true; break; - + case RESULT_DRAW: case RESULT_INVALID: break; - + default: assert(false); } } } - + return unknownFound? RESULT_UNKNOWN : RESULT_DRAW; } @@ -344,5 +345,5 @@ namespace { int compress_result(Result r) { return (r == RESULT_WIN || r == RESULT_LOSS)? 1 : 0; } - -} + +}