- /// The BetaCounterType class
-
- BetaCounterType::BetaCounterType() { clear(); }
-
- void BetaCounterType::clear() {
-
- for (int i = 0; i < THREAD_MAX; i++)
- Threads[i].betaCutOffs[WHITE] = Threads[i].betaCutOffs[BLACK] = 0ULL;
- }
-
- void BetaCounterType::add(Color us, Depth d, int threadID) {
-
- // Weighted count based on depth
- Threads[threadID].betaCutOffs[us] += unsigned(d);
- }
-
- void BetaCounterType::read(Color us, int64_t& our, int64_t& their) {
-
- our = their = 0UL;
- for (int i = 0; i < THREAD_MAX; i++)
- {
- our += Threads[i].betaCutOffs[us];
- their += Threads[i].betaCutOffs[opposite_color(us)];
- }
- }
-
-
- /// The RootMoveList class
-
- // RootMoveList c'tor
-
- RootMoveList::RootMoveList(Position& pos, Move searchMoves[]) : count(0) {
-
- MoveStack mlist[MaxRootMoves];
- bool includeAllMoves = (searchMoves[0] == MOVE_NONE);
-
- // Generate all legal moves
- MoveStack* last = generate_moves(pos, mlist);
-
- // Add each move to the moves[] array
- for (MoveStack* cur = mlist; cur != last; cur++)
- {
- bool includeMove = includeAllMoves;
-
- for (int k = 0; !includeMove && searchMoves[k] != MOVE_NONE; k++)
- includeMove = (searchMoves[k] == cur->move);
-
- if (!includeMove)
- continue;
-
- // Find a quick score for the move
- StateInfo st;
- SearchStack ss[PLY_MAX_PLUS_2];
- init_ss_array(ss);
-
- moves[count].move = cur->move;
- pos.do_move(moves[count].move, st);
- 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;
- 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;
- }
- }
-