mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
We can add an integer to a Value
We have defined corresponding operators, so rely on them to streamline the code and increase readibility. No functional change.
This commit is contained in:
parent
fe23f27086
commit
c9e396b542
5 changed files with 37 additions and 36 deletions
|
@ -245,13 +245,13 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||
|
||||
// If the stronger side's king is in front of the pawn, it's a win
|
||||
if (wksq < psq && file_of(wksq) == file_of(psq))
|
||||
result = RookValueEg - Value(square_distance(wksq, psq));
|
||||
result = RookValueEg - square_distance(wksq, psq);
|
||||
|
||||
// If the weaker side's king is too far from the pawn and the rook,
|
||||
// it's a win.
|
||||
else if ( square_distance(bksq, psq) >= 3 + (pos.side_to_move() == weakSide)
|
||||
&& square_distance(bksq, rsq) >= 3)
|
||||
result = RookValueEg - Value(square_distance(wksq, psq));
|
||||
result = RookValueEg - square_distance(wksq, psq);
|
||||
|
||||
// If the pawn is far advanced and supported by the defending king,
|
||||
// the position is drawish
|
||||
|
@ -259,13 +259,12 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
|
|||
&& square_distance(bksq, psq) == 1
|
||||
&& rank_of(wksq) >= RANK_4
|
||||
&& square_distance(wksq, psq) > 2 + (pos.side_to_move() == strongSide))
|
||||
result = Value(80 - square_distance(wksq, psq) * 8);
|
||||
result = Value(80) - 8 * square_distance(wksq, psq);
|
||||
|
||||
else
|
||||
result = Value(200)
|
||||
- Value(square_distance(wksq, psq + DELTA_S) * 8)
|
||||
+ Value(square_distance(bksq, psq + DELTA_S) * 8)
|
||||
+ Value(square_distance(psq, queeningSq) * 8);
|
||||
result = Value(200) - 8 * ( square_distance(wksq, psq + DELTA_S)
|
||||
- square_distance(bksq, psq + DELTA_S)
|
||||
- square_distance(psq, queeningSq));
|
||||
|
||||
return strongSide == pos.side_to_move() ? result : -result;
|
||||
}
|
||||
|
|
|
@ -583,24 +583,23 @@ namespace {
|
|||
|
||||
assert(pos.pawn_passed(Us, s));
|
||||
|
||||
int r = int(relative_rank(Us, s) - RANK_2);
|
||||
int rr = r * (r - 1);
|
||||
Rank r = relative_rank(Us, s) - RANK_2;
|
||||
Rank rr = r * (r - 1);
|
||||
|
||||
// Base bonus based on rank
|
||||
Value mbonus = Value(17 * rr);
|
||||
Value ebonus = Value(7 * (rr + r + 1));
|
||||
Value mbonus = Value(17 * rr), ebonus = Value(7 * (rr + r + 1));
|
||||
|
||||
if (rr)
|
||||
{
|
||||
Square blockSq = s + pawn_push(Us);
|
||||
|
||||
// Adjust bonus based on the king's proximity
|
||||
ebonus += Value(square_distance(pos.king_square(Them), blockSq) * 5 * rr)
|
||||
- Value(square_distance(pos.king_square(Us ), blockSq) * 2 * rr);
|
||||
ebonus += square_distance(pos.king_square(Them), blockSq) * 5 * rr
|
||||
- square_distance(pos.king_square(Us ), blockSq) * 2 * rr;
|
||||
|
||||
// If blockSq is not the queening square then consider also a second push
|
||||
if (relative_rank(Us, blockSq) != RANK_8)
|
||||
ebonus -= Value(rr * square_distance(pos.king_square(Us), blockSq + pawn_push(Us)));
|
||||
ebonus -= rr * square_distance(pos.king_square(Us), blockSq + pawn_push(Us));
|
||||
|
||||
// If the pawn is free to advance, then increase the bonus
|
||||
if (pos.empty(blockSq))
|
||||
|
@ -634,7 +633,7 @@ namespace {
|
|||
else if (defendedSquares & blockSq)
|
||||
k += 4;
|
||||
|
||||
mbonus += Value(k * rr), ebonus += Value(k * rr);
|
||||
mbonus += k * rr, ebonus += k * rr;
|
||||
}
|
||||
} // rr != 0
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
|
|||
if ( (MiddleEdges & make_square(f, rkThem))
|
||||
&& file_of(ksq) == f
|
||||
&& relative_rank(Us, ksq) == rkThem - 1)
|
||||
safety += Value(200);
|
||||
safety += 200;
|
||||
else
|
||||
safety -= ShelterWeakness[rkUs]
|
||||
+ StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
|
||||
|
|
|
@ -61,13 +61,13 @@ namespace {
|
|||
enum NodeType { Root, PV, NonPV, SplitPointRoot, SplitPointPV, SplitPointNonPV };
|
||||
|
||||
// Dynamic razoring margin based on depth
|
||||
inline Value razor_margin(Depth d) { return Value(512 + 16 * int(d)); }
|
||||
inline Value razor_margin(Depth d) { return Value(512 + 16 * d); }
|
||||
|
||||
// Futility lookup tables (initialized at startup) and their access functions
|
||||
int FutilityMoveCounts[2][32]; // [improving][depth]
|
||||
|
||||
inline Value futility_margin(Depth d) {
|
||||
return Value(100 * int(d));
|
||||
return Value(100 * d);
|
||||
}
|
||||
|
||||
// Reduction lookup tables (initialized at startup) and their access function
|
||||
|
@ -683,7 +683,7 @@ namespace {
|
|||
// Step 10. Internal iterative deepening (skipped when in check)
|
||||
if ( depth >= (PvNode ? 5 * ONE_PLY : 8 * ONE_PLY)
|
||||
&& !ttMove
|
||||
&& (PvNode || ss->staticEval + Value(256) >= beta))
|
||||
&& (PvNode || ss->staticEval + 256 >= beta))
|
||||
{
|
||||
Depth d = depth - 2 * ONE_PLY - (PvNode ? DEPTH_ZERO : depth / 4);
|
||||
|
||||
|
@ -823,7 +823,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
|||
if (predictedDepth < 7 * ONE_PLY)
|
||||
{
|
||||
futilityValue = ss->staticEval + futility_margin(predictedDepth)
|
||||
+ Value(128) + Gains[pos.moved_piece(move)][to_sq(move)];
|
||||
+ 128 + Gains[pos.moved_piece(move)][to_sq(move)];
|
||||
|
||||
if (futilityValue <= alpha)
|
||||
{
|
||||
|
@ -1128,7 +1128,7 @@ moves_loop: // When in check and at SpNode search starts from here
|
|||
if (PvNode && bestValue > alpha)
|
||||
alpha = bestValue;
|
||||
|
||||
futilityBase = bestValue + Value(128);
|
||||
futilityBase = bestValue + 128;
|
||||
}
|
||||
|
||||
// Initialize a MovePicker object for the current position, and prepare
|
||||
|
|
33
src/types.h
33
src/types.h
|
@ -289,7 +289,7 @@ inline Value eg_value(Score s) {
|
|||
|
||||
#endif
|
||||
|
||||
#define ENABLE_SAFE_OPERATORS_ON(T) \
|
||||
#define ENABLE_BASE_OPERATORS_ON(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)); } \
|
||||
inline T operator*(int i, const T d) { return T(i * int(d)); } \
|
||||
|
@ -299,26 +299,32 @@ inline T& operator+=(T& d1, const T d2) { return d1 = d1 + d2; } \
|
|||
inline T& operator-=(T& d1, const T d2) { return d1 = d1 - d2; } \
|
||||
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
|
||||
|
||||
#define ENABLE_OPERATORS_ON(T) ENABLE_SAFE_OPERATORS_ON(T) \
|
||||
ENABLE_BASE_OPERATORS_ON(Score)
|
||||
|
||||
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||
ENABLE_BASE_OPERATORS_ON(T) \
|
||||
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
|
||||
inline T& operator--(T& d) { return d = T(int(d) - 1); } \
|
||||
inline T operator/(const T d, int i) { return T(int(d) / i); } \
|
||||
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
||||
|
||||
ENABLE_OPERATORS_ON(Value)
|
||||
ENABLE_OPERATORS_ON(PieceType)
|
||||
ENABLE_OPERATORS_ON(Piece)
|
||||
ENABLE_OPERATORS_ON(Color)
|
||||
ENABLE_OPERATORS_ON(Depth)
|
||||
ENABLE_OPERATORS_ON(Square)
|
||||
ENABLE_OPERATORS_ON(File)
|
||||
ENABLE_OPERATORS_ON(Rank)
|
||||
ENABLE_FULL_OPERATORS_ON(Value)
|
||||
ENABLE_FULL_OPERATORS_ON(PieceType)
|
||||
ENABLE_FULL_OPERATORS_ON(Piece)
|
||||
ENABLE_FULL_OPERATORS_ON(Color)
|
||||
ENABLE_FULL_OPERATORS_ON(Depth)
|
||||
ENABLE_FULL_OPERATORS_ON(Square)
|
||||
ENABLE_FULL_OPERATORS_ON(File)
|
||||
ENABLE_FULL_OPERATORS_ON(Rank)
|
||||
|
||||
#undef ENABLE_FULL_OPERATORS_ON
|
||||
#undef ENABLE_BASE_OPERATORS_ON
|
||||
|
||||
/// Additional operators to add integers to a Value
|
||||
inline Value operator+(Value v, int i) { return Value(int(v) + i); }
|
||||
inline Value operator-(Value v, int i) { return Value(int(v) - i); }
|
||||
|
||||
ENABLE_SAFE_OPERATORS_ON(Score)
|
||||
inline Value& operator+=(Value& v, int i) { return v = v + i; }
|
||||
inline Value& operator-=(Value& v, int i) { return v = v - i; }
|
||||
|
||||
/// Only declared but not defined. We don't want to multiply two scores due to
|
||||
/// a very high risk of overflow. So user should explicitly convert to integer.
|
||||
|
@ -329,9 +335,6 @@ inline Score operator/(Score s, int i) {
|
|||
return make_score(mg_value(s) / i, eg_value(s) / i);
|
||||
}
|
||||
|
||||
#undef ENABLE_OPERATORS_ON
|
||||
#undef ENABLE_SAFE_OPERATORS_ON
|
||||
|
||||
extern Value PieceValue[PHASE_NB][PIECE_NB];
|
||||
|
||||
struct ExtMove {
|
||||
|
|
Loading…
Add table
Reference in a new issue