Fix assert with very high score position
authorMarco Costalba <mcostalba@gmail.com>
Mon, 28 Dec 2015 12:14:49 +0000 (13:14 +0100)
committerJoona Kiiski <joona@zoox.com>
Wed, 30 Dec 2015 11:16:48 +0000 (11:16 +0000)
In case of a very high material score, we can
overflow VALUE_INFINITE.

This patch fixes an assert with:

position fen 7k/QQQQR3/2B5/4KN1Q/3QQ3/8/8/4R3 b - - 0 1
go depth 1

No functional change.

Resolves #546

src/endgame.cpp

index b64b3d1bff3253e55e651a2f3055b3ebfb575f0f..681b290c4711edd8d2d08fe92dd3afcc24b67fb0 100644 (file)
@@ -163,7 +163,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
       ||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
       ||(pos.count<BISHOP>(strongSide) > 1 && opposite_colors(pos.squares<BISHOP>(strongSide)[0],
                                                               pos.squares<BISHOP>(strongSide)[1])))
       ||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
       ||(pos.count<BISHOP>(strongSide) > 1 && opposite_colors(pos.squares<BISHOP>(strongSide)[0],
                                                               pos.squares<BISHOP>(strongSide)[1])))
-      result += VALUE_KNOWN_WIN;
+      result = std::min(result + VALUE_KNOWN_WIN, VALUE_MATE_IN_MAX_PLY - 1);
 
   return strongSide == pos.side_to_move() ? result : -result;
 }
 
   return strongSide == pos.side_to_move() ? result : -result;
 }