- // Find a quick score for the move
- init_ss_array(ss);
- pos.do_move(cur->move, st);
- moves[count].move = cur->move;
- moves[count].score = -qsearch(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, Depth(0), 1, 0);
- moves[count].pv[0] = cur->move;
- moves[count].pv[1] = MOVE_NONE;
- pos.undo_move(cur->move);
- count++;
- }
- sort();
- }
-
-
- // RootMoveList simple methods definitions
-
- void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {
-
- moves[moveNum].nodes = nodes;
- moves[moveNum].cumulativeNodes += nodes;
- }
-
- void RootMoveList::set_beta_counters(int moveNum, int64_t our, int64_t their) {
-
- moves[moveNum].ourBeta = our;
- moves[moveNum].theirBeta = their;
- }
-
- void RootMoveList::set_move_pv(int moveNum, const Move pv[]) {
-
- int j;
-
- for (j = 0; pv[j] != MOVE_NONE; j++)
- moves[moveNum].pv[j] = pv[j];
-
- moves[moveNum].pv[j] = MOVE_NONE;
- }
-
-
- // RootMoveList::sort() sorts the root move list at the beginning of a new
- // iteration.
-
- void RootMoveList::sort() {
-
- sort_multipv(count - 1); // Sort all items
- }
-
-
- // RootMoveList::sort_multipv() sorts the first few moves in the root move
- // list by their scores and depths. It is used to order the different PVs
- // correctly in MultiPV mode.
-
- void RootMoveList::sort_multipv(int n) {
-
- int i,j;
-
- for (i = 1; i <= n; i++)
- {
- RootMove rm = moves[i];
- for (j = i; j > 0 && moves[j - 1] < rm; j--)
- moves[j] = moves[j - 1];
-
- moves[j] = rm;
- }
- }
-
-
- // init_node() is called at the beginning of all the search functions
- // (search(), search_pv(), qsearch(), and so on) and initializes the
- // search stack object corresponding to the current node. Once every
- // NodesBetweenPolls nodes, init_node() also calls poll(), which polls
- // for user input and checks whether it is time to stop the search.
-
- void init_node(SearchStack ss[], int ply, int threadID) {
-
- assert(ply >= 0 && ply < PLY_MAX);
- assert(threadID >= 0 && threadID < ActiveThreads);
-
- Threads[threadID].nodes++;
-
- if (threadID == 0)
- {
- NodesSincePoll++;
- if (NodesSincePoll >= NodesBetweenPolls)
- {
- poll();
- NodesSincePoll = 0;
- }
- }
- ss[ply].init(ply);
- ss[ply + 2].initKillers();
-
- if (Threads[threadID].printCurrentLine)
- print_current_line(ss, ply, threadID);
- }
-
-
- // update_pv() is called whenever a search returns a value > alpha.
- // It updates the PV in the SearchStack object corresponding to the
- // current node.
-
- void update_pv(SearchStack ss[], int ply) {
-
- assert(ply >= 0 && ply < PLY_MAX);
-
- int p;
-
- ss[ply].pv[ply] = ss[ply].currentMove;
-
- for (p = ply + 1; ss[ply + 1].pv[p] != MOVE_NONE; p++)
- ss[ply].pv[p] = ss[ply + 1].pv[p];
-
- ss[ply].pv[p] = MOVE_NONE;