From 9de4ee6d329b6da4f6bda0387a8ce6918c4e5a99 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 18 Aug 2012 10:43:13 +0100 Subject: [PATCH] Retire MovePickerExt struct Templetize MovePicker::next_move() member function instead. It is easier and we also avoid the forwarding of MovePicker() c'tor arguments in the common case. Suggested by Rein Halbersma. No functional change. Signed-off-by: Marco Costalba --- src/movepick.cpp | 18 +++++++++++++----- src/movepick.h | 3 ++- src/search.cpp | 27 ++++----------------------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/movepick.cpp b/src/movepick.cpp index 78181748..e3d29f81 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -23,6 +23,7 @@ #include "movegen.h" #include "movepick.h" +#include "thread.h" namespace { @@ -58,13 +59,14 @@ namespace { /// move ordering is at the current node. MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, - Search::Stack* ss, Value beta) : pos(p), H(h), depth(d) { + Search::Stack* s, Value beta) : pos(p), H(h), depth(d) { assert(d > DEPTH_ZERO); captureThreshold = 0; curMove = lastMove = moves; lastBadCapture = moves + MAX_MOVES - 1; + ss = s; if (p.in_check()) phase = EVASION; @@ -270,10 +272,9 @@ void MovePicker::generate_next() { /// It returns a new pseudo legal move every time it is called, until there /// are no more moves left. It picks the move with the biggest score from a list /// of generated moves taking care not to return the tt move if has already been -/// searched previously. Note that this function is not thread safe so should be -/// lock protected by caller when accessed through a shared MovePicker object. - -Move MovePicker::next_move() { +/// searched previously. +template<> +Move MovePicker::next_move() { Move move; @@ -354,3 +355,10 @@ Move MovePicker::next_move() { } } } + + +/// Version of next_move() to use at split point nodes where the move is grabbed +/// from the split point's shared MovePicker object. This function is not thread +/// safe so should be lock protected by the caller. +template<> +Move MovePicker::next_move() { return ss->sp->mp->next_move(); } diff --git a/src/movepick.h b/src/movepick.h index 03305ebd..6b5d89c0 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -41,7 +41,7 @@ public: MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value); MovePicker(const Position&, Move, Depth, const History&, Square); MovePicker(const Position&, Move, const History&, PieceType); - Move next_move(); + template Move next_move(); private: void score_captures(); @@ -51,6 +51,7 @@ private: const Position& pos; const History& H; + Search::Stack* ss; Depth depth; Move ttMove; MoveStack killers[2]; diff --git a/src/search.cpp b/src/search.cpp index 472d5372..65f5a6ad 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -146,25 +146,6 @@ namespace { Move do_skill_level(); string uci_pv(const Position& pos, int depth, Value alpha, Value beta); - // MovePickerExt class template 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 struct MovePickerExt : public MovePicker { - - MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b) - : MovePicker(p, ttm, d, h, ss, b) {} - }; - - // In case of a SpNode we use split point's shared MovePicker object as moves source - template<> struct MovePickerExt : public MovePicker { - - MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b) - : MovePicker(p, ttm, d, h, ss, b), mp(ss->sp->mp) {} - - Move next_move() { return mp->next_move(); } - MovePicker* mp; - }; - // is_dangerous() checks whether a move belongs to some classes of known // 'dangerous' moves so that we avoid to prune it. FORCE_INLINE bool is_dangerous(const Position& pos, Move m, bool captureOrPromotion) { @@ -779,7 +760,7 @@ namespace { MovePicker mp(pos, ttMove, H, pos.captured_piece_type()); CheckInfo ci(pos); - while ((move = mp.next_move()) != MOVE_NONE) + while ((move = mp.next_move()) != MOVE_NONE) if (pos.pl_move_is_legal(move, ci.pinned)) { ss->currentMove = move; @@ -808,7 +789,7 @@ namespace { split_point_start: // At split points actual search starts from here - MovePickerExt mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta); + MovePicker mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta); CheckInfo ci(pos); futilityBase = ss->eval + ss->evalMargin; singularExtensionNode = !RootNode @@ -822,7 +803,7 @@ split_point_start: // At split points actual search starts from here // Step 11. Loop through moves // Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs while ( bestValue < beta - && (move = mp.next_move()) != MOVE_NONE + && (move = mp.next_move()) != MOVE_NONE && !thisThread->cutoff_occurred() && !Signals.stop) { @@ -1213,7 +1194,7 @@ split_point_start: // At split points actual search starts from here // Loop through the moves until no moves remain or a beta cutoff occurs while ( bestValue < beta - && (move = mp.next_move()) != MOVE_NONE) + && (move = mp.next_move()) != MOVE_NONE) { assert(is_ok(move)); -- 2.39.2