-
- // Tracing functions
-
- double Tracing::to_cp(Value v) { return double(v) / PawnValueEg; }
-
- void Tracing::write(int idx, Color c, Score s) { scores[c][idx] = s; }
-
- void Tracing::write(int idx, Score w, Score b) {
- scores[WHITE][idx] = w, scores[BLACK][idx] = b;
+ // Evaluate space for both sides, only during opening
+ if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) >= 12222)
+ score += (evaluate_space<WHITE>(pos, ei) - evaluate_space<BLACK>(pos, ei)) * Weights[Space];
+
+ // Scale winning side if position is more drawish than it appears
+ Color strongSide = eg_value(score) > VALUE_DRAW ? WHITE : BLACK;
+ ScaleFactor sf = me->scale_factor(pos, strongSide);
+
+ // If we don't already have an unusual scale factor, check for certain
+ // types of endgames, and use a lower scale for those.
+ if ( me->game_phase() < PHASE_MIDGAME
+ && (sf == SCALE_FACTOR_NORMAL || sf == SCALE_FACTOR_ONEPAWN))
+ {
+ if (pos.opposite_bishops())
+ {
+ // Endgame with opposite-colored bishops and no other pieces (ignoring pawns)
+ // is almost a draw, in case of KBP vs KB is even more a draw.
+ if ( pos.non_pawn_material(WHITE) == BishopValueMg
+ && pos.non_pawn_material(BLACK) == BishopValueMg)
+ sf = more_than_one(pos.pieces(PAWN)) ? ScaleFactor(31) : ScaleFactor(9);
+
+ // Endgame with opposite-colored bishops, but also other pieces. Still
+ // a bit drawish, but not as drawish as with only the two bishops.
+ else
+ sf = ScaleFactor(46 * sf / SCALE_FACTOR_NORMAL);
+ }
+ // Endings where weaker side can place his king in front of the opponent's
+ // pawns are drawish.
+ else if ( abs(eg_value(score)) <= BishopValueEg
+ && ei.pi->pawn_span(strongSide) <= 1
+ && !pos.pawn_passed(~strongSide, pos.square<KING>(~strongSide)))
+ sf = ei.pi->pawn_span(strongSide) ? ScaleFactor(51) : ScaleFactor(37);