mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 17:49:35 +00:00
Merge pull request #3 from glinscott/b46bf29
Detect stalemate in evaluation
This commit is contained in:
commit
576f0f6985
2 changed files with 18 additions and 3 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "bitcount.h"
|
||||
#include "endgame.h"
|
||||
#include "movegen.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
@ -132,6 +133,13 @@ Value Endgame<KXK>::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<MV_LEGAL>(pos).size()) {
|
||||
return VALUE_DRAW;
|
||||
}
|
||||
|
||||
Square winnerKSq = pos.king_square(strongerSide);
|
||||
Square loserKSq = pos.king_square(weakerSide);
|
||||
|
||||
|
@ -142,9 +150,9 @@ Value Endgame<KXK>::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.both_color_bishops(strongerSide)) {
|
||||
result += VALUE_KNOWN_WIN;
|
||||
}
|
||||
|
||||
return strongerSide == pos.side_to_move() ? result : -result;
|
||||
}
|
||||
|
|
|
@ -189,6 +189,7 @@ public:
|
|||
template<bool SkipRepetition> bool is_draw() const;
|
||||
int startpos_ply_counter() const;
|
||||
bool opposite_colored_bishops() const;
|
||||
bool both_color_bishops(Color c) const;
|
||||
bool has_pawn_on_7th(Color c) const;
|
||||
bool is_chess960() const;
|
||||
|
||||
|
@ -432,6 +433,12 @@ inline bool Position::opposite_colored_bishops() const {
|
|||
&& opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]);
|
||||
}
|
||||
|
||||
inline bool Position::both_color_bishops(Color c) const {
|
||||
// Assumes that there are only two bishops
|
||||
return pieceCount[c][BISHOP] >= 2 &&
|
||||
opposite_colors(pieceList[c][BISHOP][0], pieceList[c][BISHOP][1]);
|
||||
}
|
||||
|
||||
inline bool Position::has_pawn_on_7th(Color c) const {
|
||||
return pieces(PAWN, c) & rank_bb(relative_rank(c, RANK_7));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue