- /// 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 RootMove class
-
- // Constructor
-
- RootMove::RootMove() {
- nodes = cumulativeNodes = ourBeta = theirBeta = 0ULL;
- }
-
- // RootMove::operator<() is the comparison function used when
- // sorting the moves. A move m1 is considered to be better
- // than a move m2 if it has a higher score, or if the moves
- // have equal score but m1 has the higher node count.
-
- bool RootMove::operator<(const RootMove& m) {
-
- if (score != m.score)
- return (score < m.score);
-
- return theirBeta <= m.theirBeta;
- }
-
- /// The RootMoveList class
-
- // Constructor
-
- 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; // FIXME
- count++;
- }
- sort();
- }
-
-
- // Simple accessor methods for the RootMoveList class
-
- inline Move RootMoveList::get_move(int moveNum) const {
- return moves[moveNum].move;
- }
-
- inline Value RootMoveList::get_move_score(int moveNum) const {
- return moves[moveNum].score;
- }
-
- inline void RootMoveList::set_move_score(int moveNum, Value score) {
- moves[moveNum].score = score;
- }
-
- inline void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {
- moves[moveNum].nodes = nodes;
- moves[moveNum].cumulativeNodes += nodes;
- }
-
- inline 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;
- }
-
- inline Move RootMoveList::get_move_pv(int moveNum, int i) const {
- return moves[moveNum].pv[i];
- }
-
- inline int64_t RootMoveList::get_move_cumulative_nodes(int moveNum) const {
- return moves[moveNum].cumulativeNodes;
- }