X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fendgame.cpp;h=65f0f409de3df7daa8b38ae0636f3dc69323c236;hp=00c707267575d816c5c0d12750768b9fa9610038;hb=e1919384a23fe728422f995369161efa192380db;hpb=d98150dffc69a810b0b842244aec0d29deddabfb diff --git a/src/endgame.cpp b/src/endgame.cpp index 00c70726..65f0f409 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -22,7 +22,7 @@ #include "bitcount.h" #include "endgame.h" -#include "pawns.h" +#include "movegen.h" using std::string; @@ -77,7 +77,7 @@ namespace { string fen = sides[0] + char('0' + int(8 - code.length())) + sides[1] + "/8/8/8/8/8/8/8 w - - 0 10"; - return Position(fen, false, 0).material_key(); + return Position(fen, false).material_key(); } template @@ -116,10 +116,8 @@ Endgames::~Endgames() { template void Endgames::add(const string& code) { - typedef typename eg_family::type T; - - map((T*)0)[key(code, WHITE)] = new Endgame(WHITE); - map((T*)0)[key(code, BLACK)] = new Endgame(BLACK); + map((Endgame*)0)[key(code, WHITE)] = new Endgame(WHITE); + map((Endgame*)0)[key(code, BLACK)] = new Endgame(BLACK); } @@ -133,6 +131,13 @@ Value Endgame::operator()(const Position& pos) const { assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO); assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO); + // Stalemate detection with lone king + if ( pos.side_to_move() == weakerSide + && !pos.in_check() + && !MoveList(pos).size()) { + return VALUE_DRAW; + } + Square winnerKSq = pos.king_square(strongerSide); Square loserKSq = pos.king_square(weakerSide); @@ -143,9 +148,9 @@ Value Endgame::operator()(const Position& pos) const { if ( pos.piece_count(strongerSide, QUEEN) || pos.piece_count(strongerSide, ROOK) - || pos.piece_count(strongerSide, BISHOP) > 1) - // TODO: check for two equal-colored bishops! - result += VALUE_KNOWN_WIN; + || pos.bishop_pair(strongerSide)) { + result += VALUE_KNOWN_WIN; + } return strongerSide == pos.side_to_move() ? result : -result; } @@ -416,7 +421,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { && abs(file_of(kingSq) - pawnFile) <= 1) { // The bishop has the wrong color, and the defending king is on the - // file of the pawn(s) or the neighboring file. Find the rank of the + // file of the pawn(s) or the adjacent file. Find the rank of the // frontmost pawn. Rank rank; if (strongerSide == WHITE) @@ -768,7 +773,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { return SCALE_FACTOR_NONE; case 1: - // Pawns on neighboring files. Draw if defender firmly controls the square + // Pawns on adjacent files. Draw if defender firmly controls the square // in front of the frontmost pawn's path, and the square diagonally behind // this square on the file of the other pawn. if ( ksq == blockSq1