]> git.sesse.net Git - stockfish/blobdiff - src/endgame.cpp
Replace std::mins/max with clamp function (#2062)
[stockfish] / src / endgame.cpp
index 66ee54d846044c90d03ec4dcaf9699e07aae13ee..b1b3d664288ea9fbbae4cf7070c040dff1363294 100644 (file)
@@ -18,7 +18,6 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <algorithm>
 #include <cassert>
 
 #include "bitboard.h"
@@ -131,7 +130,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
   Square loserKSq = pos.square<KING>(weakSide);
   Square bishopSq = pos.square<BISHOP>(strongSide);
 
-  // If our Bishop does not attack A1/H8, we flip the enemy king square 
+  // If our Bishop does not attack A1/H8, we flip the enemy king square
   // to drive to opposite corners (A8/H1).
 
   Value result =  VALUE_KNOWN_WIN
@@ -286,6 +285,21 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
 }
 
 
+/// KNN vs KP. Simply push the opposing king to the corner.
+template<>
+Value Endgame<KNNKP>::operator()(const Position& pos) const {
+
+    assert(verify_material(pos, strongSide, 2 * KnightValueMg, 0));
+    assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
+
+    Value result =  2 * KnightValueEg
+                  - PawnValueEg
+                  + PushToEdges[pos.square<KING>(weakSide)];
+
+    return strongSide == pos.side_to_move() ? result : -result;
+}
+
+
 /// Some cases of trivial draws
 template<> Value Endgame<KNNK>::operator()(const Position&) const { return VALUE_DRAW; }
 
@@ -724,6 +738,9 @@ ScaleFactor Endgame<KNPK>::operator()(const Position& pos) const {
 template<>
 ScaleFactor Endgame<KNPKB>::operator()(const Position& pos) const {
 
+  assert(verify_material(pos, strongSide, KnightValueMg, 1));
+  assert(verify_material(pos, weakSide, BishopValueMg, 0));
+
   Square pawnSq = pos.square<PAWN>(strongSide);
   Square bishopSq = pos.square<BISHOP>(weakSide);
   Square weakKingSq = pos.square<KING>(weakSide);