]> git.sesse.net Git - stockfish/commitdiff
Introduce enum VALUE_ZERO instead of Value(0)
authorMarco Costalba <mcostalba@gmail.com>
Wed, 18 Aug 2010 16:31:44 +0000 (17:31 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 19 Aug 2010 12:48:38 +0000 (13:48 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/endgame.cpp
src/evaluate.cpp
src/evaluate.h
src/material.cpp
src/position.cpp
src/search.cpp
src/types.h
src/value.h

index 24c8c5d41c344dd3cd501d6e955024eb7988ff17..913be63f1702c21eb4d76277c2cc4a6daaeb3954 100644 (file)
@@ -115,8 +115,8 @@ void init_bitbases() {
 template<>
 Value EvaluationFunction<KXK>::apply(const Position& pos) const {
 
 template<>
 Value EvaluationFunction<KXK>::apply(const Position& pos) const {
 
-  assert(pos.non_pawn_material(weakerSide) == Value(0));
-  assert(pos.piece_count(weakerSide, PAWN) == Value(0));
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
+  assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
 
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
 
   Square winnerKSq = pos.king_square(strongerSide);
   Square loserKSq = pos.king_square(weakerSide);
@@ -141,8 +141,8 @@ Value EvaluationFunction<KXK>::apply(const Position& pos) const {
 template<>
 Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
 
 template<>
 Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
 
-  assert(pos.non_pawn_material(weakerSide) == Value(0));
-  assert(pos.piece_count(weakerSide, PAWN) == Value(0));
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
+  assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
   assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, KNIGHT) == 1);
   assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame);
   assert(pos.piece_count(strongerSide, BISHOP) == 1);
   assert(pos.piece_count(strongerSide, KNIGHT) == 1);
@@ -173,8 +173,8 @@ Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
 template<>
 Value EvaluationFunction<KPK>::apply(const Position& pos) const {
 
 template<>
 Value EvaluationFunction<KPK>::apply(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == Value(0));
-  assert(pos.non_pawn_material(weakerSide) == Value(0));
+  assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   assert(pos.piece_count(strongerSide, PAWN) == 1);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
@@ -367,12 +367,12 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) const {
 /// king alone are always draw.
 template<>
 Value EvaluationFunction<KmmKm>::apply(const Position&) const {
 /// king alone are always draw.
 template<>
 Value EvaluationFunction<KmmKm>::apply(const Position&) const {
-  return Value(0);
+  return VALUE_ZERO;
 }
 
 template<>
 Value EvaluationFunction<KNNK>::apply(const Position&) const {
 }
 
 template<>
 Value EvaluationFunction<KNNK>::apply(const Position&) const {
-  return Value(0);
+  return VALUE_ZERO;
 }
 
 /// KBPKScalingFunction scales endgames where the stronger side has king,
 }
 
 /// KBPKScalingFunction scales endgames where the stronger side has king,
@@ -625,9 +625,9 @@ ScaleFactor ScalingFunction<KRPPKRP>::apply(const Position& pos) const {
 template<>
 ScaleFactor ScalingFunction<KPsK>::apply(const Position& pos) const {
 
 template<>
 ScaleFactor ScalingFunction<KPsK>::apply(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == Value(0));
+  assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
   assert(pos.piece_count(strongerSide, PAWN) >= 2);
   assert(pos.piece_count(strongerSide, PAWN) >= 2);
-  assert(pos.non_pawn_material(weakerSide) == Value(0));
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   Square ksq = pos.king_square(weakerSide);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   Square ksq = pos.king_square(weakerSide);
@@ -824,7 +824,7 @@ ScaleFactor ScalingFunction<KNPK>::apply(const Position& pos) const {
   assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
   assert(pos.piece_count(strongerSide, KNIGHT) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
   assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame);
   assert(pos.piece_count(strongerSide, KNIGHT) == 1);
   assert(pos.piece_count(strongerSide, PAWN) == 1);
-  assert(pos.non_pawn_material(weakerSide) == Value(0));
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
   assert(pos.piece_count(weakerSide, PAWN) == 0);
 
   Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
@@ -851,8 +851,8 @@ ScaleFactor ScalingFunction<KNPK>::apply(const Position& pos) const {
 template<>
 ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
 
 template<>
 ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
 
-  assert(pos.non_pawn_material(strongerSide) == Value(0));
-  assert(pos.non_pawn_material(weakerSide) == Value(0));
+  assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
+  assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
   assert(pos.piece_count(WHITE, PAWN) == 1);
   assert(pos.piece_count(BLACK, PAWN) == 1);
 
   assert(pos.piece_count(WHITE, PAWN) == 1);
   assert(pos.piece_count(BLACK, PAWN) == 1);
 
index f6a2ed0dcdb0ad3b1d7daf4371f7d6cbe8c12c96..47d5eb3e9bc93760432f369c04195afff4f20ac3 100644 (file)
@@ -372,8 +372,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei) {
   // colored bishop endgames, and use a lower scale for those
   if (   phase < PHASE_MIDGAME
       && pos.opposite_colored_bishops()
   // colored bishop endgames, and use a lower scale for those
   if (   phase < PHASE_MIDGAME
       && pos.opposite_colored_bishops()
-      && (   (factor[WHITE] == SCALE_FACTOR_NORMAL && eg_value(ei.value) > Value(0))
-          || (factor[BLACK] == SCALE_FACTOR_NORMAL && eg_value(ei.value) < Value(0))))
+      && (   (factor[WHITE] == SCALE_FACTOR_NORMAL && eg_value(ei.value) > VALUE_ZERO)
+          || (factor[BLACK] == SCALE_FACTOR_NORMAL && eg_value(ei.value) < VALUE_ZERO)))
   {
       ScaleFactor sf;
 
   {
       ScaleFactor sf;
 
@@ -1074,7 +1074,7 @@ namespace {
     assert(ph >= PHASE_ENDGAME && ph <= PHASE_MIDGAME);
 
     Value eg = eg_value(v);
     assert(ph >= PHASE_ENDGAME && ph <= PHASE_MIDGAME);
 
     Value eg = eg_value(v);
-    ScaleFactor f = sf[eg > Value(0) ? WHITE : BLACK];
+    ScaleFactor f = sf[eg > VALUE_ZERO ? WHITE : BLACK];
     Value ev = Value((eg * int(f)) / SCALE_FACTOR_NORMAL);
 
     int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
     Value ev = Value((eg * int(f)) / SCALE_FACTOR_NORMAL);
 
     int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
index 754d52f618621131867fcd04ec967fb33412b386..75e1f9150cc77958014207a4f81b21ecd9e1e6b4 100644 (file)
@@ -47,7 +47,7 @@ class Position;
 
 struct EvalInfo {
 
 
 struct EvalInfo {
 
-  EvalInfo() { kingDanger[0] = kingDanger[1] = Value(0); }
+  EvalInfo() { kingDanger[0] = kingDanger[1] = VALUE_ZERO; }
 
   // Middle game and endgame evaluations
   Score value;
 
   // Middle game and endgame evaluations
   Score value;
index e19b0c9e4225f9636821a9f841793184a01a106c..ffc549ca6962bb637e9d23059bb991a76f792563 100644 (file)
@@ -72,7 +72,7 @@ namespace {
   // Helper templates used to detect a given material distribution
   template<Color Us> bool is_KXK(const Position& pos) {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
   // Helper templates used to detect a given material distribution
   template<Color Us> bool is_KXK(const Position& pos) {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
-    return   pos.non_pawn_material(Them) == Value(0)
+    return   pos.non_pawn_material(Them) == VALUE_ZERO
           && pos.piece_count(Them, PAWN) == 0
           && pos.non_pawn_material(Us)   >= RookValueMidgame;
   }
           && pos.piece_count(Them, PAWN) == 0
           && pos.non_pawn_material(Us)   >= RookValueMidgame;
   }
@@ -254,7 +254,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
   else if (is_KQKRPs<BLACK>(pos))
       mi->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
 
   else if (is_KQKRPs<BLACK>(pos))
       mi->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
 
-  if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == Value(0))
+  if (pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK) == VALUE_ZERO)
   {
       if (pos.piece_count(BLACK, PAWN) == 0)
       {
   {
       if (pos.piece_count(BLACK, PAWN) == 0)
       {
index 021113ed7ded96ad2e99c243e356b2ce271cc6ae..058fab66b13940b2db943aef8548c46b63d1e936 100644 (file)
@@ -1686,7 +1686,7 @@ Score Position::compute_value() const {
 
 Value Position::compute_non_pawn_material(Color c) const {
 
 
 Value Position::compute_non_pawn_material(Color c) const {
 
-  Value result = Value(0);
+  Value result = VALUE_ZERO;
 
   for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
   {
 
   for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
   {
index 032ff4034153e1ed8acc939e1fc39a60b5f0795b..59025fba1215d78525890a6e56b44251281bbf0a 100644 (file)
@@ -996,7 +996,7 @@ namespace {
 
     // Step 2. Check for aborted search and immediate draw
     if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
 
     // Step 2. Check for aborted search and immediate draw
     if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
-        return Value(0);
+        return VALUE_ZERO;
 
     if (pos.is_draw() || ply >= PLY_MAX - 1)
         return VALUE_DRAW;
 
     if (pos.is_draw() || ply >= PLY_MAX - 1)
         return VALUE_DRAW;
@@ -1493,7 +1493,7 @@ namespace {
       {
           futilityValue =  futilityBase
                          + pos.endgame_value_of_piece_on(move_to(move))
       {
           futilityValue =  futilityBase
                          + pos.endgame_value_of_piece_on(move_to(move))
-                         + (move_is_ep(move) ? PawnValueEndgame : Value(0));
+                         + (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
 
           if (futilityValue < alpha)
           {
 
           if (futilityValue < alpha)
           {
@@ -1884,7 +1884,7 @@ namespace {
     if (   captureOrPromotion
         && pos.type_of_piece_on(move_to(m)) != PAWN
         && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
     if (   captureOrPromotion
         && pos.type_of_piece_on(move_to(m)) != PAWN
         && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
-            - pos.midgame_value_of_piece_on(move_to(m)) == Value(0))
+            - pos.midgame_value_of_piece_on(move_to(m)) == VALUE_ZERO)
         && !move_is_promotion(m)
         && !move_is_ep(m))
     {
         && !move_is_promotion(m)
         && !move_is_ep(m))
     {
index d81e7e80a33f3c391c9bf530996a3a61c2d40e71..226d76e44d63a3607a8c2e45452871522c2e0460 100644 (file)
@@ -110,8 +110,10 @@ inline void __cpuid(int CPUInfo[4], int)
 #endif
 
 
 #endif
 
 
-// Templetized enum operations, we avoid to repeat the same inlines for each
-// different enum.
+// Templetized operators used by enum types like Depth, Piece, Square and so on.
+// We don't want to write the same inline for each different enum. Note that we
+// pass by value (to silence scaring warnings on volatiles), so you really should
+// use only enum types with these functions to avoid hidden copies.
 
 template<typename T>
 inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); }
 
 template<typename T>
 inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); }
@@ -120,7 +122,10 @@ template<typename T>
 inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); }
 
 template<typename T>
 inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); }
 
 template<typename T>
-inline T operator* (int i, const T d) { return T(int(d) * i); }
+inline T operator* (int i, const T d) { return T(i * int(d)); }
+
+template<typename T>
+inline T operator* (const T d, int i) { return T(int(d) * i); }
 
 template<typename T>
 inline T operator/ (const T d, int i) { return T(int(d) / i); }
 
 template<typename T>
 inline T operator/ (const T d, int i) { return T(int(d) / i); }
@@ -144,6 +149,6 @@ template<typename T>
 inline void operator*= (T& d, int i) { d = T(int(d) * i); }
 
 template<typename T>
 inline void operator*= (T& d, int i) { d = T(int(d) * i); }
 
 template<typename T>
-inline void operator/= (T &d, int i) { d = T(int(d) / i); }
+inline void operator/= (Td, int i) { d = T(int(d) / i); }
 
 #endif // !defined(TYPES_H_INCLUDED)
 
 #endif // !defined(TYPES_H_INCLUDED)
index 512cc2f90aef7a8d725782a258922ba40bfd8b81..d47ad544d2e4df6a877ae45ce5126c7df1d89907 100644 (file)
@@ -41,6 +41,7 @@ enum ValueType {
 
 
 enum Value {
 
 
 enum Value {
+  VALUE_ZERO      = 0,
   VALUE_DRAW      = 0,
   VALUE_KNOWN_WIN = 15000,
   VALUE_MATE      = 30000,
   VALUE_DRAW      = 0,
   VALUE_KNOWN_WIN = 15000,
   VALUE_MATE      = 30000,
@@ -113,23 +114,23 @@ const Value QueenValueMidgame  = Value(0x9D9);
 const Value QueenValueEndgame  = Value(0x9FE);
 
 const Value PieceValueMidgame[17] = {
 const Value QueenValueEndgame  = Value(0x9FE);
 
 const Value PieceValueMidgame[17] = {
-  Value(0),
+  VALUE_ZERO,
   PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
   RookValueMidgame, QueenValueMidgame,
   PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
   RookValueMidgame, QueenValueMidgame,
-  Value(0), Value(0), Value(0),
+  VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
   PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
   RookValueMidgame, QueenValueMidgame,
   PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
   RookValueMidgame, QueenValueMidgame,
-  Value(0), Value(0), Value(0)
+  VALUE_ZERO, VALUE_ZERO, VALUE_ZERO
 };
 
 const Value PieceValueEndgame[17] = {
 };
 
 const Value PieceValueEndgame[17] = {
-  Value(0),
+  VALUE_ZERO,
   PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
   RookValueEndgame, QueenValueEndgame,
   PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
   RookValueEndgame, QueenValueEndgame,
-  Value(0), Value(0), Value(0),
+  VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
   PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
   RookValueEndgame, QueenValueEndgame,
   PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
   RookValueEndgame, QueenValueEndgame,
-  Value(0), Value(0), Value(0)
+  VALUE_ZERO, VALUE_ZERO, VALUE_ZERO
 };
 
 /// Bonus for having the side to move (modified by Joona Kiiski)
 };
 
 /// Bonus for having the side to move (modified by Joona Kiiski)