mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Sort root moves moves in MovePickerExt
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
5bad5fc0a7
commit
d91d6da3c4
1 changed files with 31 additions and 42 deletions
|
@ -146,8 +146,6 @@ namespace {
|
||||||
typedef std::vector<RootMove> Base;
|
typedef std::vector<RootMove> Base;
|
||||||
|
|
||||||
void init(Position& pos, Move searchMoves[]);
|
void init(Position& pos, Move searchMoves[]);
|
||||||
void set_non_pv_scores(const Position& pos, Move ttm, SearchStack* ss);
|
|
||||||
|
|
||||||
void sort() { insertion_sort<RootMove, Base::iterator>(begin(), end()); }
|
void sort() { insertion_sort<RootMove, Base::iterator>(begin(), end()); }
|
||||||
void sort_multipv(int n) { insertion_sort<RootMove, Base::iterator>(begin(), begin() + n); }
|
void sort_multipv(int n) { insertion_sort<RootMove, Base::iterator>(begin(), begin() + n); }
|
||||||
|
|
||||||
|
@ -327,11 +325,30 @@ namespace {
|
||||||
// A dispatcher to choose among different move sources according to the type of node
|
// A dispatcher to choose among different move sources according to the type of node
|
||||||
template<bool SpNode, bool Root> struct MovePickerExt;
|
template<bool SpNode, bool Root> struct MovePickerExt;
|
||||||
|
|
||||||
// In Root nodes use RootMoveList Rml as source
|
// In Root nodes use RootMoveList Rml as source. Score and sort the moves before to search them.
|
||||||
template<> struct MovePickerExt<false, true> {
|
template<> struct MovePickerExt<false, true> : private MovePicker {
|
||||||
|
|
||||||
MovePickerExt(const Position&, Move, Depth, const History&, SearchStack*, Value)
|
MovePickerExt(const Position& p, Move, Depth, const History& h, SearchStack* ss, Value beta)
|
||||||
: rm(Rml.begin()), firstCall(true) {}
|
: MovePicker(p, Rml[0].pv[0], ONE_PLY, h, ss, beta), firstCall(true) { // FIXME use depth
|
||||||
|
|
||||||
|
Move move;
|
||||||
|
Value score = VALUE_ZERO;
|
||||||
|
|
||||||
|
// Score root moves using the standard way used in main search, the moves
|
||||||
|
// are scored according to the order in which are returned by MovePicker.
|
||||||
|
// This is the second order score that is used to compare the moves when
|
||||||
|
// the first order pv scores of both moves are equal.
|
||||||
|
while ((move = MovePicker::get_next_move()) != MOVE_NONE)
|
||||||
|
for (rm = Rml.begin(); rm != Rml.end(); ++rm)
|
||||||
|
if (rm->pv[0] == move)
|
||||||
|
{
|
||||||
|
rm->non_pv_score = score--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rml.sort();
|
||||||
|
rm = Rml.begin();
|
||||||
|
}
|
||||||
|
|
||||||
Move get_next_move() {
|
Move get_next_move() {
|
||||||
|
|
||||||
|
@ -658,14 +675,10 @@ namespace {
|
||||||
// research with bigger window until we are not failing high/low anymore.
|
// research with bigger window until we are not failing high/low anymore.
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// Sort the moves before to (re)search
|
|
||||||
Rml.set_non_pv_scores(pos, Rml[0].pv[0], ss);
|
|
||||||
Rml.sort();
|
|
||||||
|
|
||||||
// Search to the current depth
|
// Search to the current depth
|
||||||
value = search<PV, false, true>(pos, ss, alpha, beta, depth, 0);
|
value = search<PV, false, true>(pos, ss, alpha, beta, depth, 0);
|
||||||
|
|
||||||
// Sort the moves and write PV lines to transposition table, in case
|
// Sort root moves and write PV lines to transposition table, in case
|
||||||
// the relevant entries have been overwritten during the search.
|
// the relevant entries have been overwritten during the search.
|
||||||
Rml.sort();
|
Rml.sort();
|
||||||
for (int i = 0; i < Min(MultiPV, (int)Rml.size()); i++)
|
for (int i = 0; i < Min(MultiPV, (int)Rml.size()); i++)
|
||||||
|
@ -673,7 +686,7 @@ namespace {
|
||||||
|
|
||||||
// Value cannot be trusted. Break out immediately!
|
// Value cannot be trusted. Break out immediately!
|
||||||
if (StopRequest)
|
if (StopRequest)
|
||||||
break;
|
break; // FIXME move to 'while' condition
|
||||||
|
|
||||||
assert(value >= alpha);
|
assert(value >= alpha);
|
||||||
|
|
||||||
|
@ -802,13 +815,12 @@ namespace {
|
||||||
}
|
}
|
||||||
else if (Root)
|
else if (Root)
|
||||||
bestValue = alpha;
|
bestValue = alpha;
|
||||||
else {} // Hack to fix icc's "statement is unreachable" warning FIXME
|
|
||||||
|
|
||||||
// Step 1. Initialize node and poll. Polling can abort search
|
// Step 1. Initialize node and poll. Polling can abort search
|
||||||
ss->currentMove = ss->bestMove = threatMove = MOVE_NONE;
|
ss->currentMove = ss->bestMove = threatMove = MOVE_NONE;
|
||||||
(ss+2)->killers[0] = (ss+2)->killers[1] = (ss+2)->mateKiller = MOVE_NONE;
|
(ss+2)->killers[0] = (ss+2)->killers[1] = (ss+2)->mateKiller = MOVE_NONE;
|
||||||
|
|
||||||
if (!Root)
|
if (!Root) // FIXME remove
|
||||||
{
|
{
|
||||||
if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls)
|
if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls)
|
||||||
{
|
{
|
||||||
|
@ -1273,15 +1285,12 @@ split_point_start: // At split points actual search starts from here
|
||||||
for (int j = 0; j < Min(MultiPV, (int)Rml.size()); j++)
|
for (int j = 0; j < Min(MultiPV, (int)Rml.size()); j++)
|
||||||
cout << Rml[j].pv_info_to_uci(pos, depth, alpha, beta, j) << endl;
|
cout << Rml[j].pv_info_to_uci(pos, depth, alpha, beta, j) << endl;
|
||||||
|
|
||||||
// Update alpha. In multi-pv we don't use aspiration window
|
// Update alpha. In multi-pv we don't use aspiration window, so
|
||||||
if (MultiPV == 1)
|
// set alpha equal to minimum score among the PV lines.
|
||||||
{
|
if (MultiPV > 1)
|
||||||
// Raise alpha to setup proper non-pv search upper bound
|
|
||||||
if (value > alpha)
|
|
||||||
alpha = value;
|
|
||||||
}
|
|
||||||
else // Set alpha equal to minimum score among the PV lines
|
|
||||||
alpha = Rml[Min(moveCount, MultiPV) - 1].pv_score; // FIXME why moveCount?
|
alpha = Rml[Min(moveCount, MultiPV) - 1].pv_score; // FIXME why moveCount?
|
||||||
|
else if (value > alpha)
|
||||||
|
alpha = value;
|
||||||
|
|
||||||
} // PV move or new best move
|
} // PV move or new best move
|
||||||
}
|
}
|
||||||
|
@ -2618,24 +2627,4 @@ split_point_start: // At split points actual search starts from here
|
||||||
sort();
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Score root moves using the standard way used in main search, the moves
|
|
||||||
// are scored according to the order in which are returned by MovePicker.
|
|
||||||
// This is the second order score that is used to compare the moves when
|
|
||||||
// the first order pv scores of both moves are equal.
|
|
||||||
|
|
||||||
void RootMoveList::set_non_pv_scores(const Position& pos, Move ttm, SearchStack* ss)
|
|
||||||
{
|
|
||||||
Move move;
|
|
||||||
Value score = VALUE_ZERO;
|
|
||||||
MovePicker mp(pos, ttm, ONE_PLY, H, ss);
|
|
||||||
|
|
||||||
while ((move = mp.get_next_move()) != MOVE_NONE)
|
|
||||||
for (Base::iterator it = begin(); it != end(); ++it)
|
|
||||||
if (it->pv[0] == move)
|
|
||||||
{
|
|
||||||
it->non_pv_score = score--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Add table
Reference in a new issue