- // init_node() is called at the beginning of all the search functions
- // (search() 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 < TM.active_threads());
-
- TM.incrementNodeCounter(threadID);
-
- if (threadID == 0)
- {
- NodesSincePoll++;
- if (NodesSincePoll >= NodesBetweenPolls)
- {
- poll();
- NodesSincePoll = 0;
- }
- }
- ss[ply].init(ply);
- ss[ply + 2].initKillers();
- }
-
- // 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;
- }
-
-
- // sp_update_pv() is a variant of update_pv for use at split points. The
- // difference between the two functions is that sp_update_pv also updates
- // the PV at the parent node.
-
- void sp_update_pv(SearchStack* pss, SearchStack ss[], int ply) {
-
- assert(ply >= 0 && ply < PLY_MAX);
-
- int p;
-
- ss[ply].pv[ply] = pss[ply].pv[ply] = ss[ply].currentMove;
-
- for (p = ply + 1; ss[ply + 1].pv[p] != MOVE_NONE; p++)
- ss[ply].pv[p] = pss[ply].pv[p] = ss[ply + 1].pv[p];
-
- ss[ply].pv[p] = pss[ply].pv[p] = MOVE_NONE;
- }
-