- Value bestMoveValue = this->get_move_score(0);
- for(int i = 1; i < this->move_count(); i++)
- if(this->get_move_score(i) >= bestMoveValue - EasyMoveMargin)
- return MOVE_NONE;
- return this->get_move(0);
+ assert(count);
+
+ if (count == 1)
+ return get_move(0);
+
+ // moves are sorted so just consider the best and the second one
+ if (get_move_score(0) > get_move_score(1) + EasyMoveMargin)
+ return get_move(0);
+
+ return MOVE_NONE;
+ }
+
+
+ // RootMoveList::compare_root_moves() is the comparison function used by
+ // RootMoveList::sort 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 RootMoveList::compare_root_moves(const RootMove &rm1,
+ const RootMove &rm2) {
+ if (rm1.score != rm2.score)
+ return (rm1.score < rm2.score);
+
+ return rm1.nodes <= rm2.nodes;