inline Move get_move_pv(int moveNum, int i) const;
inline int64_t get_move_cumulative_nodes(int moveNum) const;
inline int move_count() const;
- Move scan_for_easy_move() const;
inline void sort();
void sort_multipv(int n);
<< " moves to go: " << movesToGo << std::endl;
- // We're ready to start thinking. Call the iterative deepening loop function
- //
- // FIXME we really need to cleanup all this LSN ugliness
- if (!loseOnTime)
+ // LSN filtering. Used only for developing purpose. Disabled by default.
+ if ( UseLSNFiltering
+ && loseOnTime)
{
- Value v = id_loop(pos, searchMoves);
- loseOnTime = ( UseLSNFiltering
- && myTime < LSNTime
- && myIncrement == 0
- && v < -LSNValue);
+ // Step 2. If after last move we decided to lose on time, do it now!
+ while (SearchStartTime + myTime + 1000 > get_system_time())
+ ; // wait here
}
- else
+
+ // We're ready to start thinking. Call the iterative deepening loop function
+ Value v = id_loop(pos, searchMoves);
+
+ // LSN filtering. Used only for developing purpose. Disabled by default.
+ if (UseLSNFiltering)
{
- loseOnTime = false; // reset for next match
- while (SearchStartTime + myTime + 1000 > get_system_time())
- ; // wait here
- id_loop(pos, searchMoves); // to fail gracefully
+ // 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
+ && movesToGo == 0
+ && v < -LSNValue)
+ {
+ loseOnTime = true;
+ }
+ else if (loseOnTime)
+ {
+ // Step 3. Now after stepping over the time limit, reset flag for next match.
+ loseOnTime = false;
+ }
}
if (UseLogFile)
IterationInfo[1] = IterationInfoType(rml.get_move_score(0), rml.get_move_score(0));
Iteration = 1;
- Move EasyMove = rml.scan_for_easy_move();
+ // Is one move significantly better than others after initial scoring ?
+ Move EasyMove = MOVE_NONE;
+ if ( rml.move_count() == 1
+ || rml.get_move_score(0) > rml.get_move_score(1) + EasyMoveMargin)
+ EasyMove = rml.get_move(0);
// Iterative deepening loop
while (Iteration < PLY_MAX)
if (stopSearch)
{
- //FIXME: Implement fail-low emergency measures
if (!PonderSearch)
break;
else
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 >= 8 * 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
// 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;
}
}
moves[count].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, Depth(0), 1, 0);
pos.undo_move(moves[count].move);
moves[count].pv[0] = moves[count].move;
- moves[count].pv[1] = MOVE_NONE; // FIXME
+ moves[count].pv[1] = MOVE_NONE;
count++;
}
sort();
}
- // RootMoveList::scan_for_easy_move() is called at the end of the first
- // iteration, and is used to detect an "easy move", i.e. a move which appears
- // to be much bester than all the rest. If an easy move is found, the move
- // is returned, otherwise the function returns MOVE_NONE. It is very
- // important that this function is called at the right moment: The code
- // assumes that the first iteration has been completed and the moves have
- // been sorted. This is done in RootMoveList c'tor.
-
- Move RootMoveList::scan_for_easy_move() const {
-
- assert(count);
-
- if (count == 1)
- return get_move(0);
-
- // moves are sorted so just consider the best and the second one
- if (get_move_score(0) > get_move_score(1) + EasyMoveMargin)
- return get_move(0);
-
- return MOVE_NONE;
- }
-
// RootMoveList::sort() sorts the root move list at the beginning of a new
// iteration.