- // Different node types, used as template parameter
- enum NodeType { Root, PV, NonPV, SplitPointPV, SplitPointNonPV };
-
- // RootMove struct is used for moves at the root of the tree. For each root
- // move, we store two scores, a node count, and a PV (really a refutation
- // in the case of moves which fail low). Value pv_score is normally set at
- // -VALUE_INFINITE for all non-pv moves, while non_pv_score is computed
- // according to the order in which moves are returned by MovePicker.
- struct RootMove {
-
- RootMove();
- RootMove(const RootMove& rm) { *this = rm; }
- RootMove& operator=(const RootMove& rm);
-
- // 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 an higher pv_score, or if it has
- // equal pv_score but m1 has the higher non_pv_score. In this way
- // we are guaranteed that PV moves are always sorted as first.
- bool operator<(const RootMove& m) const {
- return pv_score != m.pv_score ? pv_score < m.pv_score
- : non_pv_score < m.non_pv_score;
- }
-
- void extract_pv_from_tt(Position& pos);
- void insert_pv_in_tt(Position& pos);
- std::string pv_info_to_uci(Position& pos, int depth, int selDepth,
- Value alpha, Value beta, int pvIdx);
- int64_t nodes;
- Value pv_score;
- Value non_pv_score;
- Move pv[PLY_MAX_PLUS_2];
- };
-
- // RootMoveList struct is just a vector of RootMove objects,
- // with an handful of methods above the standard ones.
- struct RootMoveList : public std::vector<RootMove> {
-
- typedef std::vector<RootMove> Base;
-
- void init(Position& pos, Move searchMoves[]);
- void sort() { insertion_sort<RootMove, Base::iterator>(begin(), end()); }
- void sort_multipv(int n) { insertion_sort<RootMove, Base::iterator>(begin(), begin() + n); }
-
- int bestMoveChanges;
- };
-
- // MovePickerExt template class extends MovePicker and allows to choose at compile
- // time the proper moves source according to the type of node. In the default case
- // we simply create and use a standard MovePicker object.
- template<NodeType> struct MovePickerExt : 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
- };
-
- // In case of a SpNode we use split point's shared MovePicker object as moves source
- template<> struct MovePickerExt<SplitPointNonPV> : public MovePickerExt<NonPV> {
-
- MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
- : MovePickerExt<NonPV>(p, ttm, d, h, ss, b), mp(ss->sp->mp) {}
-
- Move get_next_move() { return mp->get_next_move(); }
- MovePicker* mp;
- };
-
- template<> struct MovePickerExt<SplitPointPV> : public MovePickerExt<SplitPointNonPV> {
-
- MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
- : MovePickerExt<SplitPointNonPV>(p, ttm, d, h, ss, b) {}
- };
-
- // In case of a Root node we use RootMoveList as moves source
- template<> struct MovePickerExt<Root> : public MovePicker {
-
- MovePickerExt(const Position&, Move, Depth, const History&, SearchStack*, Value);
- Move get_next_move();
-
- RootMoveList::iterator rm;
- bool firstCall;
- };
-
-
- /// Constants
-
- // Lookup table to check if a Piece is a slider and its access function
- const bool Slidings[18] = { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 };
- inline bool piece_is_slider(Piece p) { return Slidings[p]; }