mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Unify stats update()
Now that is a bit bigger makes sense to unify some duplicated code. No functional change.
This commit is contained in:
parent
ae6a4ebf1f
commit
9001f55147
1 changed files with 16 additions and 26 deletions
|
@ -35,6 +35,20 @@ struct StatBoards : public std::array<std::array<T, Size2>, Size1> {
|
||||||
T* p = &(*this)[0][0];
|
T* p = &(*this)[0][0];
|
||||||
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
std::fill(p, p + sizeof(*this) / sizeof(*p), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update(T& entry, int bonus, const int D) {
|
||||||
|
|
||||||
|
assert([&]{
|
||||||
|
int v = entry + bonus * 32 - entry * abs(bonus) / D;
|
||||||
|
return INT16_MIN < v && v < INT16_MAX;
|
||||||
|
}());
|
||||||
|
|
||||||
|
assert(abs(bonus) <= D); // Consistency check for below formula
|
||||||
|
|
||||||
|
entry += bonus * 32 - entry * abs(bonus) / D;
|
||||||
|
|
||||||
|
assert(abs(entry) <= 32 * D);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
|
/// ButterflyBoards are 2 tables (one for each color) indexed by the move's from
|
||||||
|
@ -50,19 +64,7 @@ typedef StatBoards<PIECE_NB, SQUARE_NB> PieceToBoards;
|
||||||
struct ButterflyHistory : public ButterflyBoards {
|
struct ButterflyHistory : public ButterflyBoards {
|
||||||
|
|
||||||
void update(Color c, Move m, int bonus) {
|
void update(Color c, Move m, int bonus) {
|
||||||
|
StatBoards::update((*this)[c][from_to(m)], bonus, 324);
|
||||||
const int D = 324;
|
|
||||||
auto& entry = (*this)[c][from_to(m)];
|
|
||||||
|
|
||||||
assert(abs(bonus) <= D); // Consistency check for below formula
|
|
||||||
assert([&]{
|
|
||||||
int v = entry + bonus * 32 - entry * abs(bonus) / D;
|
|
||||||
return INT16_MIN < v && v < INT16_MAX;
|
|
||||||
}());
|
|
||||||
|
|
||||||
entry += bonus * 32 - entry * abs(bonus) / D;
|
|
||||||
|
|
||||||
assert(abs(entry) <= 32 * D);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,19 +72,7 @@ struct ButterflyHistory : public ButterflyBoards {
|
||||||
struct PieceToHistory : public PieceToBoards {
|
struct PieceToHistory : public PieceToBoards {
|
||||||
|
|
||||||
void update(Piece pc, Square to, int bonus) {
|
void update(Piece pc, Square to, int bonus) {
|
||||||
|
StatBoards::update((*this)[pc][to], bonus, 936);
|
||||||
const int D = 936;
|
|
||||||
auto& entry = (*this)[pc][to];
|
|
||||||
|
|
||||||
assert(abs(bonus) <= D); // Consistency check for below formula
|
|
||||||
assert([&]{
|
|
||||||
int v = entry + bonus * 32 - entry * abs(bonus) / D;
|
|
||||||
return INT16_MIN < v && v < INT16_MAX;
|
|
||||||
}());
|
|
||||||
|
|
||||||
entry += bonus * 32 - entry * abs(bonus) / D;
|
|
||||||
|
|
||||||
assert(abs(entry) <= 32 * D);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue