mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 08:13:08 +00:00
Introduce enum VALUE_ZERO instead of Value(0)
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
0e800c527a
commit
94b9c65e09
8 changed files with 39 additions and 33 deletions
|
@ -115,8 +115,8 @@ void init_bitbases() {
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KXK>::apply(const Position& pos) const {
|
Value EvaluationFunction<KXK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
|
||||||
assert(pos.piece_count(weakerSide, PAWN) == Value(0));
|
assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
|
||||||
|
|
||||||
Square winnerKSq = pos.king_square(strongerSide);
|
Square winnerKSq = pos.king_square(strongerSide);
|
||||||
Square loserKSq = pos.king_square(weakerSide);
|
Square loserKSq = pos.king_square(weakerSide);
|
||||||
|
@ -141,8 +141,8 @@ Value EvaluationFunction<KXK>::apply(const Position& pos) const {
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
|
Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
|
||||||
assert(pos.piece_count(weakerSide, PAWN) == Value(0));
|
assert(pos.piece_count(weakerSide, PAWN) == VALUE_ZERO);
|
||||||
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame);
|
assert(pos.non_pawn_material(strongerSide) == KnightValueMidgame + BishopValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
assert(pos.piece_count(strongerSide, BISHOP) == 1);
|
||||||
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
|
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
|
||||||
|
@ -173,8 +173,8 @@ Value EvaluationFunction<KBNK>::apply(const Position& pos) const {
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KPK>::apply(const Position& pos) const {
|
Value EvaluationFunction<KPK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 1);
|
assert(pos.piece_count(strongerSide, PAWN) == 1);
|
||||||
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
||||||
|
|
||||||
|
@ -367,12 +367,12 @@ Value EvaluationFunction<KBBKN>::apply(const Position& pos) const {
|
||||||
/// king alone are always draw.
|
/// king alone are always draw.
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KmmKm>::apply(const Position&) const {
|
Value EvaluationFunction<KmmKm>::apply(const Position&) const {
|
||||||
return Value(0);
|
return VALUE_ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
Value EvaluationFunction<KNNK>::apply(const Position&) const {
|
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<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KPsK>::apply(const Position& pos) const {
|
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);
|
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
||||||
|
|
||||||
Square ksq = pos.king_square(weakerSide);
|
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.non_pawn_material(strongerSide) == KnightValueMidgame);
|
||||||
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
|
assert(pos.piece_count(strongerSide, KNIGHT) == 1);
|
||||||
assert(pos.piece_count(strongerSide, PAWN) == 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);
|
assert(pos.piece_count(weakerSide, PAWN) == 0);
|
||||||
|
|
||||||
Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
|
Square pawnSq = pos.piece_list(strongerSide, PAWN, 0);
|
||||||
|
@ -851,8 +851,8 @@ ScaleFactor ScalingFunction<KNPK>::apply(const Position& pos) const {
|
||||||
template<>
|
template<>
|
||||||
ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
|
ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
assert(pos.non_pawn_material(strongerSide) == Value(0));
|
assert(pos.non_pawn_material(strongerSide) == VALUE_ZERO);
|
||||||
assert(pos.non_pawn_material(weakerSide) == Value(0));
|
assert(pos.non_pawn_material(weakerSide) == VALUE_ZERO);
|
||||||
assert(pos.piece_count(WHITE, PAWN) == 1);
|
assert(pos.piece_count(WHITE, PAWN) == 1);
|
||||||
assert(pos.piece_count(BLACK, PAWN) == 1);
|
assert(pos.piece_count(BLACK, PAWN) == 1);
|
||||||
|
|
||||||
|
|
|
@ -372,8 +372,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei) {
|
||||||
// colored bishop endgames, and use a lower scale for those
|
// colored bishop endgames, and use a lower scale for those
|
||||||
if ( phase < PHASE_MIDGAME
|
if ( phase < PHASE_MIDGAME
|
||||||
&& pos.opposite_colored_bishops()
|
&& pos.opposite_colored_bishops()
|
||||||
&& ( (factor[WHITE] == 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(0))))
|
|| (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);
|
assert(ph >= PHASE_ENDGAME && ph <= PHASE_MIDGAME);
|
||||||
|
|
||||||
Value eg = eg_value(v);
|
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);
|
Value ev = Value((eg * int(f)) / SCALE_FACTOR_NORMAL);
|
||||||
|
|
||||||
int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
|
int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
|
||||||
|
|
|
@ -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
|
// Middle game and endgame evaluations
|
||||||
Score value;
|
Score value;
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace {
|
||||||
// Helper templates used to detect a given material distribution
|
// Helper templates used to detect a given material distribution
|
||||||
template<Color Us> bool is_KXK(const Position& pos) {
|
template<Color Us> bool is_KXK(const Position& pos) {
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
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.piece_count(Them, PAWN) == 0
|
||||||
&& pos.non_pawn_material(Us) >= RookValueMidgame;
|
&& pos.non_pawn_material(Us) >= RookValueMidgame;
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
|
||||||
else if (is_KQKRPs<BLACK>(pos))
|
else if (is_KQKRPs<BLACK>(pos))
|
||||||
mi->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
|
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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -996,7 +996,7 @@ namespace {
|
||||||
|
|
||||||
// Step 2. Check for aborted search and immediate draw
|
// Step 2. Check for aborted search and immediate draw
|
||||||
if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
|
if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
|
||||||
return Value(0);
|
return VALUE_ZERO;
|
||||||
|
|
||||||
if (pos.is_draw() || ply >= PLY_MAX - 1)
|
if (pos.is_draw() || ply >= PLY_MAX - 1)
|
||||||
return VALUE_DRAW;
|
return VALUE_DRAW;
|
||||||
|
@ -1493,7 +1493,7 @@ namespace {
|
||||||
{
|
{
|
||||||
futilityValue = futilityBase
|
futilityValue = futilityBase
|
||||||
+ pos.endgame_value_of_piece_on(move_to(move))
|
+ 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
|
if ( captureOrPromotion
|
||||||
&& pos.type_of_piece_on(move_to(m)) != PAWN
|
&& pos.type_of_piece_on(move_to(m)) != PAWN
|
||||||
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
|
&& ( 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_promotion(m)
|
||||||
&& !move_is_ep(m))
|
&& !move_is_ep(m))
|
||||||
{
|
{
|
||||||
|
|
13
src/types.h
13
src/types.h
|
@ -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
|
// Templetized operators used by enum types like Depth, Piece, Square and so on.
|
||||||
// different enum.
|
// 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>
|
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)); }
|
||||||
|
@ -120,7 +122,10 @@ 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>
|
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>
|
template<typename T>
|
||||||
inline T operator/ (const T d, int i) { return T(int(d) / i); }
|
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); }
|
inline void operator*= (T& d, int i) { d = T(int(d) * i); }
|
||||||
|
|
||||||
template<typename T>
|
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)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|
13
src/value.h
13
src/value.h
|
@ -41,6 +41,7 @@ enum ValueType {
|
||||||
|
|
||||||
|
|
||||||
enum Value {
|
enum Value {
|
||||||
|
VALUE_ZERO = 0,
|
||||||
VALUE_DRAW = 0,
|
VALUE_DRAW = 0,
|
||||||
VALUE_KNOWN_WIN = 15000,
|
VALUE_KNOWN_WIN = 15000,
|
||||||
VALUE_MATE = 30000,
|
VALUE_MATE = 30000,
|
||||||
|
@ -113,23 +114,23 @@ const Value QueenValueMidgame = Value(0x9D9);
|
||||||
const Value QueenValueEndgame = Value(0x9FE);
|
const Value QueenValueEndgame = Value(0x9FE);
|
||||||
|
|
||||||
const Value PieceValueMidgame[17] = {
|
const Value PieceValueMidgame[17] = {
|
||||||
Value(0),
|
VALUE_ZERO,
|
||||||
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
||||||
RookValueMidgame, QueenValueMidgame,
|
RookValueMidgame, QueenValueMidgame,
|
||||||
Value(0), Value(0), Value(0),
|
VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
|
||||||
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
||||||
RookValueMidgame, QueenValueMidgame,
|
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,
|
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
|
||||||
RookValueEndgame, QueenValueEndgame,
|
RookValueEndgame, QueenValueEndgame,
|
||||||
Value(0), Value(0), Value(0),
|
VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
|
||||||
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
|
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
|
||||||
RookValueEndgame, QueenValueEndgame,
|
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue