From 94b9c65e09b5d396bebb29b62d9979139b5fbdfa Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 18 Aug 2010 17:31:44 +0100 Subject: [PATCH 1/1] Introduce enum VALUE_ZERO instead of Value(0) No functional change. Signed-off-by: Marco Costalba --- src/endgame.cpp | 26 +++++++++++++------------- src/evaluate.cpp | 6 +++--- src/evaluate.h | 2 +- src/material.cpp | 4 ++-- src/position.cpp | 2 +- src/search.cpp | 6 +++--- src/types.h | 13 +++++++++---- src/value.h | 13 +++++++------ 8 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/endgame.cpp b/src/endgame.cpp index 24c8c5d4..913be63f 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -115,8 +115,8 @@ void init_bitbases() { template<> Value EvaluationFunction::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); @@ -141,8 +141,8 @@ Value EvaluationFunction::apply(const Position& pos) const { template<> Value EvaluationFunction::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); @@ -173,8 +173,8 @@ Value EvaluationFunction::apply(const Position& pos) const { template<> Value EvaluationFunction::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); @@ -367,12 +367,12 @@ Value EvaluationFunction::apply(const Position& pos) const { /// king alone are always draw. template<> Value EvaluationFunction::apply(const Position&) const { - return Value(0); + return VALUE_ZERO; } template<> Value EvaluationFunction::apply(const Position&) const { - return Value(0); + return VALUE_ZERO; } /// KBPKScalingFunction scales endgames where the stronger side has king, @@ -625,9 +625,9 @@ ScaleFactor ScalingFunction::apply(const Position& pos) const { template<> ScaleFactor ScalingFunction::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.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); @@ -824,7 +824,7 @@ ScaleFactor ScalingFunction::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(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); @@ -851,8 +851,8 @@ ScaleFactor ScalingFunction::apply(const Position& pos) const { template<> ScaleFactor ScalingFunction::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); diff --git a/src/evaluate.cpp b/src/evaluate.cpp index f6a2ed0d..47d5eb3e 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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() - && ( (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; @@ -1074,7 +1074,7 @@ namespace { 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; diff --git a/src/evaluate.h b/src/evaluate.h index 754d52f6..75e1f915 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -47,7 +47,7 @@ class Position; struct EvalInfo { - EvalInfo() { kingDanger[0] = kingDanger[1] = Value(0); } + EvalInfo() { kingDanger[0] = kingDanger[1] = VALUE_ZERO; } // Middle game and endgame evaluations Score value; diff --git a/src/material.cpp b/src/material.cpp index e19b0c9e..ffc549ca 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -72,7 +72,7 @@ namespace { // Helper templates used to detect a given material distribution template 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; } @@ -254,7 +254,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) { else if (is_KQKRPs(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) { diff --git a/src/position.cpp b/src/position.cpp index 021113ed..058fab66 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1686,7 +1686,7 @@ Score Position::compute_value() 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++) { diff --git a/src/search.cpp b/src/search.cpp index 032ff403..59025fba 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -996,7 +996,7 @@ namespace { // 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; @@ -1493,7 +1493,7 @@ namespace { { 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) { @@ -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) - - 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)) { diff --git a/src/types.h b/src/types.h index d81e7e80..226d76e4 100644 --- a/src/types.h +++ b/src/types.h @@ -110,8 +110,10 @@ inline void __cpuid(int CPUInfo[4], int) #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 inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } @@ -120,7 +122,10 @@ template inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); } template -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 +inline T operator* (const T d, int i) { return T(int(d) * i); } template inline T operator/ (const T d, int i) { return T(int(d) / i); } @@ -144,6 +149,6 @@ template inline void operator*= (T& d, int i) { d = T(int(d) * i); } template -inline void operator/= (T &d, int i) { d = T(int(d) / i); } +inline void operator/= (T& d, int i) { d = T(int(d) / i); } #endif // !defined(TYPES_H_INCLUDED) diff --git a/src/value.h b/src/value.h index 512cc2f9..d47ad544 100644 --- a/src/value.h +++ b/src/value.h @@ -41,6 +41,7 @@ enum ValueType { enum Value { + VALUE_ZERO = 0, 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] = { - Value(0), + VALUE_ZERO, PawnValueMidgame, KnightValueMidgame, BishopValueMidgame, RookValueMidgame, QueenValueMidgame, - Value(0), Value(0), Value(0), + VALUE_ZERO, VALUE_ZERO, VALUE_ZERO, PawnValueMidgame, KnightValueMidgame, BishopValueMidgame, RookValueMidgame, QueenValueMidgame, - Value(0), Value(0), Value(0) + VALUE_ZERO, VALUE_ZERO, VALUE_ZERO }; const Value PieceValueEndgame[17] = { - Value(0), + VALUE_ZERO, PawnValueEndgame, KnightValueEndgame, BishopValueEndgame, RookValueEndgame, QueenValueEndgame, - Value(0), Value(0), Value(0), + VALUE_ZERO, VALUE_ZERO, VALUE_ZERO, 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) -- 2.39.2