1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Revert store of distinct upper and lower bounds

Test by Joona prooves the new feature don't value 70 added lines of code.

Grand totals after 10040 games (crashes: 0) for tt_both

master_9edc7 - 6a93488_6a934: 1756 - 1688 - 6596 ELO +2 (+- 2.7)

Confirmed by test of Gary:

After 8680 games:
ELO: 0.80 +- 99%: 9.62 95%: 7.31
LOS: 65.38%
Wins: 1288 Losses: 1268 Draws: 6130

Thanks a lot to both for testing it !!!

bench 5149248
This commit is contained in:
Marco Costalba 2012-12-15 11:11:38 +01:00
parent 9edc7d6958
commit a2f46446cf
4 changed files with 41 additions and 111 deletions

View file

@ -482,7 +482,7 @@ namespace {
Key posKey;
Move ttMove, move, excludedMove, bestMove, threatMove;
Depth ext, newDepth;
Value bestValue, value, ttValue, ttValueUpper;
Value bestValue, value, ttValue;
Value eval, nullValue, futilityValue;
bool inCheck, givesCheck, pvMove, singularExtensionNode;
bool captureOrPromotion, dangerous, doFullDepthSearch;
@ -544,43 +544,31 @@ namespace {
tte = TT.probe(posKey);
ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE;
ttValue = tte ? value_from_tt(tte->value(), ss->ply) : VALUE_NONE;
ttValueUpper = tte ? value_from_tt(tte->value_upper(), ss->ply) : VALUE_NONE;
// At PV nodes we check for exact scores, while at non-PV nodes we check for
// a fail high/low. Biggest advantage at probing at PV nodes is to have a
// smooth experience in analysis mode. We don't probe at Root nodes otherwise
// we should also update RootMoveList to avoid bogus output.
if (!RootNode && tte)
if ( !RootNode
&& tte
&& tte->depth() >= depth
&& ttValue != VALUE_NONE // Only in case of TT access race
&& ( PvNode ? tte->type() == BOUND_EXACT
: ttValue >= beta ? (tte->type() & BOUND_LOWER)
: (tte->type() & BOUND_UPPER)))
{
// Fail High
if ( (tte->type() & BOUND_LOWER)
&& ttValue >= beta
&& tte->depth() >= depth
&& ttValue != VALUE_NONE) // Only in case of TT access race
{
// Update killers, we assume ttMove caused a cut-off
if ( ttMove
&& !pos.is_capture_or_promotion(ttMove)
&& ttMove != ss->killers[0])
{
ss->killers[1] = ss->killers[0];
ss->killers[0] = ttMove;
}
TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValue;
}
TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE
// Fail Low
if ( (tte->type() & BOUND_UPPER)
&& ttValueUpper <= alpha
&& tte->depth_upper() >= depth
&& ttValueUpper != VALUE_NONE) // Only in case of TT access race
if ( ttValue >= beta
&& ttMove
&& !pos.is_capture_or_promotion(ttMove)
&& ttMove != ss->killers[0])
{
TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValueUpper;
ss->killers[1] = ss->killers[0];
ss->killers[0] = ttMove;
}
return ttValue;
}
// Step 5. Evaluate the position statically and update parent's gain statistics
@ -1101,7 +1089,7 @@ split_point_start: // At split points actual search starts from here
const TTEntry* tte;
Key posKey;
Move ttMove, move, bestMove;
Value bestValue, value, ttValue, ttValueUpper, futilityValue, futilityBase, oldAlpha;
Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha;
bool givesCheck, enoughMaterial, evasionPrunable, fromNull;
Depth ttDepth;
@ -1123,34 +1111,21 @@ split_point_start: // At split points actual search starts from here
tte = TT.probe(posKey);
ttMove = tte ? tte->move() : MOVE_NONE;
ttValue = tte ? value_from_tt(tte->value(),ss->ply) : VALUE_NONE;
ttValueUpper = tte ? value_from_tt(tte->value_upper(),ss->ply) : VALUE_NONE;
// Decide whether or not to include checks, this fixes also the type of
// TT entry depth that we are going to use. Note that in qsearch we use
// only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
ttDepth = InCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS
: DEPTH_QS_NO_CHECKS;
if (tte)
if ( tte
&& tte->depth() >= ttDepth
&& ttValue != VALUE_NONE // Only in case of TT access race
&& ( PvNode ? tte->type() == BOUND_EXACT
: ttValue >= beta ? (tte->type() & BOUND_LOWER)
: (tte->type() & BOUND_UPPER)))
{
// Fail High
if ( (tte->type() & BOUND_LOWER)
&& ttValue >= beta
&& tte->depth() >= ttDepth
&& ttValue != VALUE_NONE) // Only in case of TT access race
{
ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValue;
}
// Fail Low
if ( (tte->type() & BOUND_UPPER)
&& ttValueUpper <= alpha
&& tte->depth_upper() >= ttDepth
&& ttValueUpper != VALUE_NONE) // Only in case of TT access race
{
ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValueUpper;
}
ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValue;
}
// Evaluate the position statically

View file

@ -82,7 +82,7 @@ void TranspositionTable::clear() {
/// more valuable than a TTEntry t2 if t1 is from the current search and t2 is from
/// a previous search, or if the depth of t1 is bigger than the depth of t2.
void TranspositionTable::store(const Key posKey, Value v, Bound b, Depth d, Move m) {
void TranspositionTable::store(const Key posKey, Value v, Bound t, Depth d, Move m) {
int c1, c2, c3;
TTEntry *tte, *replace;
@ -92,16 +92,13 @@ void TranspositionTable::store(const Key posKey, Value v, Bound b, Depth d, Move
for (int i = 0; i < ClusterSize; i++, tte++)
{
if (!tte->key())
tte->save(posKey32, v, b, d, m, generation);
if (tte->key() == posKey32)
if (!tte->key() || tte->key() == posKey32) // Empty or overwrite old
{
// Preserve any existing ttMove
if (m == MOVE_NONE)
m = tte->move();
tte->update(v, b, d, m, generation);
tte->save(posKey32, v, t, d, m, generation);
return;
}
@ -113,7 +110,7 @@ void TranspositionTable::store(const Key posKey, Value v, Bound b, Depth d, Move
if (c1 + c2 + c3 > 0)
replace = tte;
}
replace->save(posKey32, v, b, d, m, generation);
replace->save(posKey32, v, t, d, m, generation);
}

View file

@ -46,61 +46,19 @@ class TTEntry {
public:
void save(uint32_t k, Value v, Bound b, Depth d, Move m, int g) {
key32 = (uint32_t)k;
move16 = (uint16_t)m;
bound = (uint8_t)b;
generation8 = (uint8_t)g;
valueUpper = (int16_t)(b & BOUND_UPPER ? v : VALUE_NONE);
depthUpper = (int16_t)(b & BOUND_UPPER ? d : DEPTH_NONE);
valueLower = (int16_t)(b & BOUND_LOWER ? v : VALUE_NONE);
depthLower = (int16_t)(b & BOUND_LOWER ? d : DEPTH_NONE);
key32 = (uint32_t)k;
move16 = (uint16_t)m;
bound = (uint8_t)b;
generation8 = (uint8_t)g;
value16 = (int16_t)v;
depth16 = (int16_t)d;
}
void update(Value v, Bound b, Depth d, Move m, int g) {
move16 = (uint16_t)m;
generation8 = (uint8_t)g;
if (bound == BOUND_EXACT)
bound = BOUND_UPPER | BOUND_LOWER; // Drop 'EXACT' flag
if (b & BOUND_UPPER)
{
valueUpper = (int16_t)v;
depthUpper = (int16_t)d;
if ((bound & BOUND_LOWER) && v < valueLower)
{
bound ^= BOUND_LOWER;
valueLower = VALUE_NONE;
depthLower = DEPTH_NONE;
}
}
if (b & BOUND_LOWER)
{
valueLower = (int16_t)v;
depthLower = (int16_t)d;
if ((bound & BOUND_UPPER) && v > valueUpper)
{
bound ^= BOUND_UPPER;
valueUpper = VALUE_NONE;
depthUpper = DEPTH_NONE;
}
}
bound |= (uint8_t)b;
}
void set_generation(int g) { generation8 = (uint8_t)g; }
uint32_t key() const { return key32; }
Depth depth() const { return (Depth)depthLower; }
Depth depth_upper() const { return (Depth)depthUpper; }
Depth depth() const { return (Depth)depth16; }
Move move() const { return (Move)move16; }
Value value() const { return (Value)valueLower; }
Value value_upper() const { return (Value)valueUpper; }
Value value() const { return (Value)value16; }
Bound type() const { return (Bound)bound; }
int generation() const { return (int)generation8; }
@ -108,7 +66,7 @@ private:
uint32_t key32;
uint16_t move16;
uint8_t bound, generation8;
int16_t valueLower, depthLower, valueUpper, depthUpper;
int16_t value16, depth16;
};
@ -138,7 +96,7 @@ public:
~TranspositionTable();
void set_size(size_t mbSize);
void clear();
void store(const Key posKey, Value v, Bound b, Depth d, Move m);
void store(const Key posKey, Value v, Bound type, Depth d, Move m);
TTEntry* probe(const Key posKey) const;
void new_search();
TTEntry* first_entry(const Key posKey) const;

View file

@ -164,7 +164,7 @@ enum Bound {
BOUND_NONE = 0,
BOUND_UPPER = 1,
BOUND_LOWER = 2,
BOUND_EXACT = BOUND_UPPER | BOUND_LOWER | 4
BOUND_EXACT = BOUND_UPPER | BOUND_LOWER
};
enum Value {