X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=34a87771aea96a120e14f5858ffebd510f73d60f;hp=ccc3d9154d62612daea3c68ab972e42d6afb2553;hb=a9e93fa6a56d985e98f16a480a8b0d166fdea324;hpb=918c29f83ab8a013d3946916887e1d1d7b9cfb9a diff --git a/src/evaluate.cpp b/src/evaluate.cpp index ccc3d915..34a87771 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -17,10 +17,10 @@ along with this program. If not, see . */ +#include #include #include #include -#include #include "bitcount.h" #include "evaluate.h" @@ -158,6 +158,9 @@ namespace { S(0, 0), S(0, 0), S(56, 70), S(56, 70), S(76, 99), S(86, 118) }; + // Hanging[side to move] contains a bonus for each enemy hanging piece + const Score Hanging[2] = { S(23, 20) , S(35, 45) }; + #undef S const Score Tempo = make_score(24, 11); @@ -527,7 +530,7 @@ namespace { if (undefendedMinors) score += UndefendedMinor; - // Enemy pieces not defended by a pawn and under our attack + // Enemies not defended by a pawn and under our attack weakEnemies = pos.pieces(Them) & ~ei.attackedBy[Them][PAWN] & ei.attackedBy[Us][ALL_PIECES]; @@ -535,13 +538,18 @@ namespace { // Add a bonus according if the attacking pieces are minor or major if (weakEnemies) { - b = weakEnemies & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]); + b = weakEnemies & (ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]); if (b) score += Threat[0][type_of(pos.piece_on(lsb(b)))]; b = weakEnemies & (ei.attackedBy[Us][ROOK] | ei.attackedBy[Us][QUEEN]); if (b) score += Threat[1][type_of(pos.piece_on(lsb(b)))]; + + b = weakEnemies & ~ei.attackedBy[Them][ALL_PIECES]; + if (b) + score += more_than_one(b) ? Hanging[Us != pos.side_to_move()] * popcount(b) + : Hanging[Us == pos.side_to_move()]; } if (Trace) @@ -779,11 +787,18 @@ namespace { sf = ScaleFactor(50 * sf / SCALE_FACTOR_NORMAL); } - // Interpolate between a middlegame and an endgame score, scaling by 'sf' + // Stealmate detection + Color stm = pos.side_to_move(); + if ( (ei.attackedBy[stm][ALL_PIECES] == ei.attackedBy[stm][KING]) + && (!(ei.attackedBy[stm][KING] & ~ei.attackedBy[~stm][ALL_PIECES])) + && !MoveList(pos).size()) + sf = SCALE_FACTOR_DRAW; + + // Interpolate between a middlegame and a (scaled by 'sf') endgame score Value v = mg_value(score) * int(ei.mi->game_phase()) - + eg_value(score) * int(sf) / SCALE_FACTOR_NORMAL * int(PHASE_MIDGAME - ei.mi->game_phase()); + + eg_value(score) * int(PHASE_MIDGAME - ei.mi->game_phase()) * sf / SCALE_FACTOR_NORMAL; - v /= PHASE_MIDGAME; + v /= int(PHASE_MIDGAME); // In case of tracing add all single evaluation contributions for both white and black if (Trace)