No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
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);
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);
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);
/// 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 {
- return Value(0);
+ return VALUE_ZERO;
}
/// KBPKScalingFunction scales endgames where the stronger side has king,
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.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.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);
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);
// 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;
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;
struct EvalInfo {
- EvalInfo() { kingDanger[0] = kingDanger[1] = Value(0); }
+ EvalInfo() { kingDanger[0] = kingDanger[1] = VALUE_ZERO; }
// Middle game and endgame evaluations
Score value;
// 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;
}
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)
{
Value Position::compute_non_pawn_material(Color c) const {
- Value result = Value(0);
+ Value result = VALUE_ZERO;
for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
{
// 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;
{
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 ( 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))
{
#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)); }
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); }
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/= (T& d, int i) { d = T(int(d) / i); }
#endif // !defined(TYPES_H_INCLUDED)
enum Value {
+ VALUE_ZERO = 0,
VALUE_DRAW = 0,
VALUE_KNOWN_WIN = 15000,
VALUE_MATE = 30000,
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)