/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
- Copyright (C) 2008 Marco Costalba
+ Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
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.
-
+
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 <http://www.gnu.org/licenses/>.
*/
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;
Result classify_btm(const KPKPosition &p);
int compute_index(Square wksq, Square bksq, Square psq, Color stm);
int compress_result(Result r);
-
+
}
int i, j, b;
for(i = 0; i < 24576; i++) {
for(b = 0, j = 0; j < 8; b |= (compress_result(Bitbase[8*i+j]) << j), j++);
- bitbase[i] = b;
+ assert(b == int(uint8_t(b)));
+ bitbase[i] = (uint8_t)b;
}
// Release allocated memory:
return compute_index(whiteKingSquare, blackKingSquare, pawnSquare,
sideToMove);
}
-
+
bool KPKPosition::is_legal() const {
if(whiteKingSquare == pawnSquare || whiteKingSquare == blackKingSquare ||
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;
(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];
bool next_iteration() {
KPKPosition p;
int previousUnknownCount = UnknownCount;
-
+
for(int i = 0; i < IndexMax; i++)
if(Bitbase[i] == RESULT_UNKNOWN) {
p.from_index(i);
bool unknownFound = false;
Bitboard b;
Square s;
-
+
// King moves
b = p.wk_attacks();
while(b) {
BLACK)]) {
case RESULT_LOSS:
return RESULT_WIN;
-
+
case RESULT_UNKNOWN:
unknownFound = true;
break;
-
+
case RESULT_DRAW: case RESULT_INVALID:
break;
-
+
default:
assert(false);
}
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;
}
int compress_result(Result r) {
return (r == RESULT_WIN || r == RESULT_LOSS)? 1 : 0;
}
-
-}
+
+}