]> git.sesse.net Git - stockfish/commitdiff
Slight tidy up in endgame machinery
authorMarco Costalba <mcostalba@gmail.com>
Sat, 21 Jul 2018 08:30:22 +0000 (10:30 +0200)
committerStéphane Nicolet <cassio@free.fr>
Sun, 22 Jul 2018 15:55:41 +0000 (17:55 +0200)
No functional change.

src/endgame.cpp
src/endgame.h
src/evaluate.h
src/material.cpp
src/material.h

index 3e01259c9745b01d90c0e9731f5bf2a6727fdf20..5a114d705d3387d94300219b5e3c41f6e63da620 100644 (file)
@@ -86,30 +86,6 @@ namespace {
 } // namespace
 
 
 } // namespace
 
 
-/// Endgames members definitions
-
-Endgames::Endgames() {
-
-  add<KPK>("KPK");
-  add<KNNK>("KNNK");
-  add<KBNK>("KBNK");
-  add<KRKP>("KRKP");
-  add<KRKB>("KRKB");
-  add<KRKN>("KRKN");
-  add<KQKP>("KQKP");
-  add<KQKR>("KQKR");
-
-  add<KNPK>("KNPK");
-  add<KNPKB>("KNPKB");
-  add<KRPKR>("KRPKR");
-  add<KRPKB>("KRPKB");
-  add<KBPKB>("KBPKB");
-  add<KBPKN>("KBPKN");
-  add<KBPPKB>("KBPPKB");
-  add<KRPPKRP>("KRPPKRP");
-}
-
-
 /// Mate with KX vs K. This function is used to evaluate positions with
 /// king and plenty of material vs a lone king. It simply gives the
 /// attacking side a bonus for driving the defending king towards the edge
 /// Mate with KX vs K. This function is used to evaluate positions with
 /// king and plenty of material vs a lone king. It simply gives the
 /// attacking side a bonus for driving the defending king towards the edge
index b5255a2f53d74e16031cf0a3fd45b7d88df1724a..69a9f179c08e10bc9a41f139d6c9c6fb8d2860e6 100644 (file)
@@ -64,6 +64,7 @@ enum EndgameCode {
 
 /// Endgame functions can be of two types depending on whether they return a
 /// Value or a ScaleFactor.
 
 /// Endgame functions can be of two types depending on whether they return a
 /// Value or a ScaleFactor.
+
 template<EndgameCode E> using
 eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
 
 template<EndgameCode E> using
 eg_type = typename std::conditional<(E < SCALING_FUNCTIONS), Value, ScaleFactor>::type;
 
@@ -103,21 +104,40 @@ class Endgames {
     return std::get<std::is_same<T, ScaleFactor>::value>(maps);
   }
 
     return std::get<std::is_same<T, ScaleFactor>::value>(maps);
   }
 
-  template<EndgameCode E, typename T = eg_type<E>, typename P = Ptr<T>>
+  template<EndgameCode E, typename T = eg_type<E>>
   void add(const std::string& code) {
 
     StateInfo st;
   void add(const std::string& code) {
 
     StateInfo st;
-    map<T>()[Position().set(code, WHITE, &st).material_key()] = P(new Endgame<E>(WHITE));
-    map<T>()[Position().set(code, BLACK, &st).material_key()] = P(new Endgame<E>(BLACK));
+    map<T>()[Position().set(code, WHITE, &st).material_key()] = Ptr<T>(new Endgame<E>(WHITE));
+    map<T>()[Position().set(code, BLACK, &st).material_key()] = Ptr<T>(new Endgame<E>(BLACK));
   }
 
   std::pair<Map<Value>, Map<ScaleFactor>> maps;
 
 public:
   }
 
   std::pair<Map<Value>, Map<ScaleFactor>> maps;
 
 public:
-  Endgames();
+  Endgames() {
+
+    add<KPK>("KPK");
+    add<KNNK>("KNNK");
+    add<KBNK>("KBNK");
+    add<KRKP>("KRKP");
+    add<KRKB>("KRKB");
+    add<KRKN>("KRKN");
+    add<KQKP>("KQKP");
+    add<KQKR>("KQKR");
+
+    add<KNPK>("KNPK");
+    add<KNPKB>("KNPKB");
+    add<KRPKR>("KRPKR");
+    add<KRPKB>("KRPKB");
+    add<KBPKB>("KBPKB");
+    add<KBPKN>("KBPKN");
+    add<KBPPKB>("KBPPKB");
+    add<KRPPKRP>("KRPPKRP");
+  }
 
   template<typename T>
 
   template<typename T>
-  EndgameBase<T>* probe(Key key) {
+  const EndgameBase<T>* probe(Key key) {
     return map<T>().count(key) ? map<T>()[key].get() : nullptr;
   }
 };
     return map<T>().count(key) ? map<T>()[key].get() : nullptr;
   }
 };
index ccc6d5fa7b4b867e15786b328367fd99932bbfe9..d5a7e731207ff379a39f2824822143d961302567 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef EVALUATE_H_INCLUDED
 #define EVALUATE_H_INCLUDED
 
 #ifndef EVALUATE_H_INCLUDED
 #define EVALUATE_H_INCLUDED
 
-#include <atomic>
 #include <string>
 
 #include "types.h"
 #include <string>
 
 #include "types.h"
index b18d29d06b28715fec73884130ed2cd11260921f..64a5bff033f9e7579fa33c9c94c3ea3f9dec0b22 100644 (file)
@@ -152,7 +152,7 @@ Entry* probe(const Position& pos) {
 
   // OK, we didn't find any special evaluation function for the current material
   // configuration. Is there a suitable specialized scaling function?
 
   // OK, we didn't find any special evaluation function for the current material
   // configuration. Is there a suitable specialized scaling function?
-  EndgameBase<ScaleFactor>* sf;
+  const EndgameBase<ScaleFactor>* sf;
 
   if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
   {
 
   if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
   {
index 7fea5e7d2557e7d1d705f504aaade56b5ea593fb..5e6419458e7dc8dcf7c678f3fe8b8aafa97a2f27 100644 (file)
@@ -56,9 +56,9 @@ struct Entry {
   }
 
   Key key;
   }
 
   Key key;
-  EndgameBase<Value>* evaluationFunction;
-  EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
-                                                       // side (e.g. KPKP, KBPsKs)
+  const EndgameBase<Value>* evaluationFunction;
+  const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
+                                                             // side (e.g. KPKP, KBPsKs)
   int16_t value;
   uint8_t factor[COLOR_NB];
   Phase gamePhase;
   int16_t value;
   uint8_t factor[COLOR_NB];
   Phase gamePhase;