Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
- Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
+ Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, 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
} // namespace
-/// Endgames members definitions
-
-Endgames::Endgames() {
-
- add<KPK>("KPK");
- add<KNNK>("KNNK");
- add<KBNK>("KBNK");
- add<KRKP>("KRKP");
- add<KRKB>("KRKB");
- add<KRKN>("KRKN");
- add<KQKP>("KQKP");
- add<KQKR>("KQKR");
-
- add<KNPK>("KNPK");
- add<KNPKB>("KNPKB");
- add<KRPKR>("KRPKR");
- add<KRPKB>("KRPKB");
- add<KBPKB>("KBPKB");
- add<KBPKN>("KBPKN");
- add<KBPPKB>("KBPPKB");
- add<KRPPKRP>("KRPPKRP");
-}
-
-
/// Mate with KX vs K. This function is used to evaluate positions with
/// king and plenty of material vs a lone king. It simply gives the
/// attacking side a bonus for driving the defending king towards the edge
Value result;
// If the stronger side's king is in front of the pawn, it's a win
- if (wksq < psq && file_of(wksq) == file_of(psq))
+ if (forward_file_bb(WHITE, wksq) & psq)
result = RookValueEg - distance(wksq, psq);
// If the weaker side's king is too far from the pawn and the rook,
}
-/// KR vs KB. This is very simple, and always returns drawish scores. The
+/// KR vs KB. This is very simple, and always returns drawish scores. The
/// score is slightly bigger when the defending king is close to the edge.
template<>
Value Endgame<KRKB>::operator()(const Position& pos) const {
// Case 2: Opposite colored bishops
if (opposite_colors(strongBishopSq, weakBishopSq))
- {
- // We assume that the position is drawn in the following three situations:
- //
- // a. The pawn is on rank 5 or further back.
- // b. The defending king is somewhere in the pawn's path.
- // c. The defending bishop attacks some square along the pawn's path,
- // and is at least three squares away from the pawn.
- //
- // These rules are probably not perfect, but in practice they work
- // reasonably well.
-
- if (relative_rank(strongSide, pawnSq) <= RANK_5)
- return SCALE_FACTOR_DRAW;
-
- Bitboard path = forward_file_bb(strongSide, pawnSq);
-
- if (path & pos.pieces(weakSide, KING))
- return SCALE_FACTOR_DRAW;
+ return SCALE_FACTOR_DRAW;
- if ( (pos.attacks_from<BISHOP>(weakBishopSq) & path)
- && distance(weakBishopSq, pawnSq) >= 3)
- return SCALE_FACTOR_DRAW;
- }
return SCALE_FACTOR_NONE;
}