Decode the score into the protobuf.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 19 Mar 2016 21:36:16 +0000 (22:36 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 24 Nov 2018 10:17:41 +0000 (11:17 +0100)
src/client.cpp
src/hashprobe.proto
src/main.cpp

index 9f20357..6049495 100644 (file)
@@ -61,7 +61,14 @@ int main(int argc, char** argv) {
           std::cout << ">=";
           break;
         } 
-        std::cout << " " << UCI::value(Value(line.value())) << " ";
+       switch (line.value().score_type()) {
+       case HashProbeScore::SCORE_CP:
+         std::cout << " cp " << line.value().score_cp() << " ";
+          break;
+       case HashProbeScore::SCORE_MATE:
+         std::cout << " mate " << line.value().score_mate() << " ";
+          break;
+        }
         std::cout << line.depth() << std::endl;
       }
       std::cout << "END" << std::endl;
index 42f6b2b..dfd16fd 100644 (file)
@@ -13,8 +13,8 @@ message HashProbeLine {
        bool found = 2;
 
        repeated HashProbeMove pv = 3;
-       int32 value = 4;  // Dynamic eval (may be inexact, see the "bound" field)
-       int32 eval = 5;  // Static eval
+       HashProbeScore value = 4;  // Dynamic eval (may be inexact, see the "bound" field)
+       HashProbeScore eval = 5;  // Static eval
        int32 depth = 6;
 
        enum ValueBound {
@@ -31,6 +31,15 @@ message HashProbeMove {
        string to_sq = 2;
        string promotion = 3;  // Q, R, etc.
 }
+message HashProbeScore {
+       enum ScoreType {
+               SCORE_CP = 0;
+               SCORE_MATE = 1;
+       }
+       ScoreType score_type = 1;
+       int32 score_cp = 2;
+       int32 score_mate = 3;
+}
 
 service HashProbe {
        rpc Probe(HashProbeRequest) returns (HashProbeResponse) {}
index d851bda..a5ed56e 100644 (file)
@@ -107,8 +107,8 @@ public:
                        }
 
                        response->set_depth(entry->depth());
-                       response->set_eval(eval);
-                       response->set_value(value);
+                       FillValue(eval, response->mutable_eval());
+                       FillValue(value, response->mutable_value());
                        response->set_bound(HashProbeLine::ValueBound(bound));
 
                        // Follow the PV until we hit an illegal move.
@@ -131,6 +131,16 @@ public:
                        }
                }
        }
+
+       void FillValue(Value value, HashProbeScore* score) {
+               if (abs(value) < VALUE_MATE - MAX_PLY) {
+                       score->set_score_type(HashProbeScore::SCORE_CP);
+                       score->set_score_cp(value * 100 / PawnValueEg);
+               } else {
+                       score->set_score_type(HashProbeScore::SCORE_MATE);
+                       score->set_score_mate((value > 0 ? VALUE_MATE - value + 1 : -VALUE_MATE - value) / 2);
+               }
+       }
 };
        
 void rpc_thread()