+
+ // MovePickerExt is an extended MovePicker used to choose at compile time
+ // the proper move source according to the type of node.
+ template<bool SpNode, bool Root> struct MovePickerExt;
+
+ // In Root nodes use RootMoveList Rml as source. Score and sort the root moves
+ // before to search them.
+ template<> struct MovePickerExt<false, true> : public MovePicker {
+
+ MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
+ : MovePicker(p, ttm, d, h, ss, b), firstCall(true) {
+ Move move;
+ Value score = VALUE_ZERO;
+
+ // Score root moves using the standard way used in main search, the moves
+ // are scored according to the order in which are returned by MovePicker.
+ // This is the second order score that is used to compare the moves when
+ // the first order pv scores of both moves are equal.
+ while ((move = MovePicker::get_next_move()) != MOVE_NONE)
+ for (rm = Rml.begin(); rm != Rml.end(); ++rm)
+ if (rm->pv[0] == move)
+ {
+ rm->non_pv_score = score--;
+ break;
+ }
+
+ Rml.sort();
+ rm = Rml.begin();
+ }
+
+ Move get_next_move() {
+
+ if (!firstCall)
+ ++rm;
+ else
+ firstCall = false;
+
+ return rm != Rml.end() ? rm->pv[0] : MOVE_NONE;
+ }
+
+ RootMoveList::iterator rm;
+ bool firstCall;
+ };
+
+ // In SpNodes use split point's shared MovePicker object as move source
+ template<> struct MovePickerExt<true, false> : public MovePicker {
+
+ MovePickerExt(const Position& p, Move ttm, Depth d, const History& h,
+ SearchStack* ss, Value b) : MovePicker(p, ttm, d, h, ss, b),
+ mp(ss->sp->mp) {}
+
+ Move get_next_move() { return mp->get_next_move(); }
+
+ RootMoveList::iterator rm; // Dummy, needed to compile
+ MovePicker* mp;
+ };
+
+ // Default case, create and use a MovePicker object as source
+ template<> struct MovePickerExt<false, false> : public MovePicker {
+
+ MovePickerExt(const Position& p, Move ttm, Depth d, const History& h,
+ SearchStack* ss, Value b) : MovePicker(p, ttm, d, h, ss, b) {}
+
+ RootMoveList::iterator rm; // Dummy, needed to compile
+ };
+
+} // namespace