const Value FutilityMarginQS = Value(0x80);
// Each move futility margin is decreased
- const Value IncrementalFutilityMargin = Value(0x8);
+ const Value IncrementalFutilityMargin = Value(0x4);
// Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply
const Value FutilityMargins[12] = { Value(0x100), Value(0x120), Value(0x200), Value(0x220), Value(0x250), Value(0x270),
// LSN filtering. Used only for developing purpose. Disabled by default.
- if (UseLSNFiltering)
+ if ( UseLSNFiltering
+ && loseOnTime)
{
// Step 2. If after last move we decided to lose on time, do it now!
- if ( loseOnTime
- && myTime < LSNTime // double check: catches some very rear false positives!
- && myIncrement == 0
- && movesToGo == 0)
- {
- while (SearchStartTime + myTime + 1000 > get_system_time())
- ; // wait here
- } else if (loseOnTime) // false positive, reset flag
- loseOnTime = false;
+ while (SearchStartTime + myTime + 1000 > get_system_time())
+ ; // wait here
}
// We're ready to start thinking. Call the iterative deepening loop function
// LSN filtering. Used only for developing purpose. Disabled by default.
if (UseLSNFiltering)
{
- // Step 1. If this is sudden death game and our position is hopeless, decide to lose on time.
+ // Step 1. If this is sudden death game and our position is hopeless,
+ // decide to lose on time.
if ( !loseOnTime // If we already lost on time, go to step 3.
&& myTime < LSNTime
&& myIncrement == 0
return alpha;
// Transposition table lookup. At PV nodes, we don't use the TT for
- // pruning, but only for move ordering.
+ // pruning, but only for move ordering. This is to avoid problems in
+ // the following areas:
+ //
+ // * Repetition draw detection
+ // * Fifty move rule detection
+ // * Searching for a mate
+ // * Printing of full PV line
+ //
tte = TT.retrieve(pos.get_key());
ttMove = (tte ? tte->move() : MOVE_NONE);
{
search_pv(pos, ss, alpha, beta, depth-2*OnePly, ply, threadID);
ttMove = ss[ply].pv[ply];
+ tte = TT.retrieve(pos.get_key());
+
+ // If tte->move() != MOVE_NONE then it equals ttMove
+ assert(!(tte && tte->move()) || tte->move() == ttMove);
}
// Initialize a MovePicker object for the current position, and prepare
// To verify this we do a reduced search on all the other moves but the ttMove,
// if result is lower then TT value minus a margin then we assume ttMove is the
// only one playable. It is a kind of relaxed single reply extension.
- if ( depth >= 4 * OnePly
- && move == ttMove
+ if ( depth >= 6 * OnePly
+ && tte
+ && move == tte->move()
&& ext < OnePly
&& is_lower_bound(tte->type())
&& tte->depth() >= depth - 3 * OnePly)
if (abs(ttValue) < VALUE_KNOWN_WIN)
{
- Depth d = Max(Min(depth / 2, depth - 4 * OnePly), OnePly);
- Value excValue = search(pos, ss, ttValue - SingleReplyMargin, d, ply, false, threadID, ttMove);
+ Value excValue = search(pos, ss, ttValue - SingleReplyMargin, depth / 2, ply, false, threadID, move);
// If search result is well below the foreseen score of the ttMove then we
// assume ttMove is the only one realistically playable and we extend it.
{
search(pos, ss, beta, Min(depth/2, depth-2*OnePly), ply, false, threadID);
ttMove = ss[ply].pv[ply];
+ tte = TT.retrieve(pos.get_key());
}
// Initialize a MovePicker object for the current position, and prepare
// Move count pruning limit
const int MCLimit = 3 + (1 << (3*int(depth)/8));
+ /*
+ for (int d = 2; d < 16; d++)
+ std::cout << d << " -> " << 56*(0+2*bitScanReverse32(1 * int(d) * int(d) / 2)) << std::endl;
+ //std::cout << d << " -> " << 32*(1+3*bitScanReverse32(1 * int(d) * int(d))) << std::endl;
+ */
+
// Loop through all legal moves until no moves remain or a beta cutoff occurs
while ( bestValue < beta
&& (move = mp.get_next_move()) != MOVE_NONE
// To verify this we do a reduced search on all the other moves but the ttMove,
// if result is lower then TT value minus a margin then we assume ttMove is the
// only one playable. It is a kind of relaxed single reply extension.
- if ( depth >= 4 * OnePly
- && !excludedMove // do not allow recursive single-reply search
- && move == ttMove
+ if ( depth >= 8 * OnePly
+ && tte
+ && move == tte->move()
+ && !excludedMove // Do not allow recursive single-reply search
&& ext < OnePly
&& is_lower_bound(tte->type())
&& tte->depth() >= depth - 3 * OnePly)
if (abs(ttValue) < VALUE_KNOWN_WIN)
{
- Depth d = Max(Min(depth / 2, depth - 4 * OnePly), OnePly);
- Value excValue = search(pos, ss, ttValue - SingleReplyMargin, d, ply, false, threadID, ttMove);
+ Value excValue = search(pos, ss, ttValue - SingleReplyMargin, depth / 2, ply, false, threadID, move);
// If search result is well below the foreseen score of the ttMove then we
// assume ttMove is the only one realistically playable and we extend it.
if (excValue < ttValue - SingleReplyMargin)
- ext = (depth >= 8 * OnePly) ? OnePly : ext + OnePly / 2;
+ ext = OnePly;
}
}
// Value based pruning
if (approximateEval < beta)
- {
+ {//dbg_before();
if (futilityValue == VALUE_NONE)
futilityValue = evaluate(pos, ei, threadID)
- + 64*(2+bitScanReverse32(int(depth) * int(depth)));
+ + 56*(0+2*bitScanReverse32(1 * int(depth) * int(depth) / 2));
futilityValueScaled = futilityValue - moveCount * IncrementalFutilityMargin;
bestValue = futilityValueScaled;
continue;
}
+ //dbg_after(); // 36% (inc == 8), 40% (inc == 4), 37%(56)
}
}