]> git.sesse.net Git - stockfish/blobdiff - src/endgame.cpp
Better naming and document some endgame functions
[stockfish] / src / endgame.cpp
index 3f3bdcce7646ea5da05cbf68fc7228b62dc87c37..d9961622e043f93f669a83cbd4d489aaa1389fc7 100644 (file)
 #include <cassert>
 
 #include "bitbase.h"
+#include "bitcount.h"
 #include "endgame.h"
 
 
-////
-//// Constants and variables
-////
-
-/// Evaluation functions
-
-// Generic "mate lone king" eval
-EvaluationFunction<KXK> EvaluateKXK(WHITE), EvaluateKKX(BLACK);
-
-// K and two minors vs K and one or two minors
-EvaluationFunction<KmmKm> EvaluateKmmKm(WHITE);
-
-EvaluationFunction<KBNK> EvaluateKBNK(WHITE), EvaluateKKBN(BLACK); // KBN vs K
-EvaluationFunction<KPK> EvaluateKPK(WHITE), EvaluateKKP(BLACK);    // KP vs K
-EvaluationFunction<KRKP> EvaluateKRKP(WHITE), EvaluateKPKR(BLACK); // KR vs KP
-EvaluationFunction<KRKB> EvaluateKRKB(WHITE), EvaluateKBKR(BLACK); // KR vs KB
-EvaluationFunction<KRKN> EvaluateKRKN(WHITE), EvaluateKNKR(BLACK); // KR vs KN
-EvaluationFunction<KQKR> EvaluateKQKR(WHITE), EvaluateKRKQ(BLACK); // KQ vs KR
-EvaluationFunction<KBBKN> EvaluateKBBKN(WHITE), EvaluateKNKBB(BLACK); // KBB vs KN
-
-
-/// Scaling functions
-
-ScalingFunction<KBPK> ScaleKBPK(WHITE), ScaleKKBP(BLACK);    // KBP vs K
-ScalingFunction<KQKRP> ScaleKQKRP(WHITE), ScaleKRPKQ(BLACK); // KQ vs KRP
-ScalingFunction<KRPKR> ScaleKRPKR(WHITE), ScaleKRKRP(BLACK); // KRP vs KR
-ScalingFunction<KRPPKRP> ScaleKRPPKRP(WHITE), ScaleKRPKRPP(BLACK); // KRPP vs KRP
-ScalingFunction<KPsK> ScaleKPsK(WHITE), ScaleKKPs(BLACK);    // King and pawns vs king
-ScalingFunction<KBPKB> ScaleKBPKB(WHITE), ScaleKBKBP(BLACK); // KBP vs KB
-ScalingFunction<KBPPKB> ScaleKBPPKB(WHITE), ScaleKBKBPP(BLACK); // KBPP vs KB
-ScalingFunction<KBPKN> ScaleKBPKN(WHITE), ScaleKNKBP(BLACK); // KBP vs KN
-ScalingFunction<KNPK> ScaleKNPK(WHITE), ScaleKKNP(BLACK);    // KNP vs K
-ScalingFunction<KPKP> ScaleKPKPw(WHITE), ScaleKPKPb(BLACK);  // KPKP
-
-
 ////
 //// Local definitions
 ////
@@ -382,11 +348,18 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) {
   return (strongerSide == pos.side_to_move() ? result : -result);
 }
 
+
+/// K and two minors vs K and one or two minors or K and two knights against
+/// king alone are always draw.
 template<>
 Value EvaluationFunction<KmmKm>::apply(const Position&) {
   return Value(0);
 }
 
+template<>
+Value EvaluationFunction<KNNK>::apply(const Position&) {
+  return Value(0);
+}
 
 /// KBPKScalingFunction scales endgames where the stronger side has king,
 /// bishop and one or more pawns. It checks for draws with rook pawns and a
@@ -394,7 +367,7 @@ Value EvaluationFunction<KmmKm>::apply(const Position&) {
 /// returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
 /// will be used.
 template<>
-ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
+ScaleFactor ScalingFunction<KBPsK>::apply(const Position& pos) {
 
   assert(pos.non_pawn_material(strongerSide) == BishopValueMidgame);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
@@ -420,7 +393,6 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
           // The bishop has the wrong color, and the defending king is on the
           // file of the pawn(s) or the neighboring file. Find the rank of the
           // frontmost pawn.
-
           Rank rank;
           if (strongerSide == WHITE)
           {
@@ -449,7 +421,7 @@ ScaleFactor ScalingFunction<KBPK>::apply(const Position& pos) {
 /// It tests for fortress draws with a rook on the third rank defended by
 /// a pawn.
 template<>
-ScaleFactor ScalingFunction<KQKRP>::apply(const Position& pos) {
+ScaleFactor ScalingFunction<KQKRPs>::apply(const Position& pos) {
 
   assert(pos.non_pawn_material(strongerSide) == QueenValueMidgame);
   assert(pos.piece_count(strongerSide, QUEEN) == 1);