No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
/// move ordering is at the current node.
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
- SearchStack* ss, Value beta) : pos(p), H(h), depth(d) {
+ Search::Stack* ss, Value beta) : pos(p), H(h), depth(d) {
captureThreshold = 0;
badCaptures = moves + MAX_MOVES;
#include "history.h"
#include "position.h"
+#include "search.h"
#include "types.h"
-struct SearchStack;
-
/// MovePicker is a class which is used to pick one pseudo legal move at a time
/// from the current position. It is initialized with a Position object and a few
/// moves we have reason to believe are good. The most important method is
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
public:
- MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
+ MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value);
MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
MovePicker(const Position&, Move, const History&, PieceType parentCapture);
Move get_next_move();
#include "tt.h"
#include "ucioption.h"
-using std::cout;
-using std::endl;
-using std::string;
-using Search::Signals;
-using Search::Limits;
-
namespace Search {
volatile SignalsType Signals;
Position RootPosition;
}
+using std::cout;
+using std::endl;
+using std::string;
+using namespace Search;
+
namespace {
// Set to true to force running with one thread. Used for debugging
Move id_loop(Position& pos, Move rootMoves[], Move* ponderMove);
template <NodeType NT>
- Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth);
+ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
template <NodeType NT>
- Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth);
+ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth);
bool check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta, Value *bValue);
bool connected_moves(const Position& pos, Move m1, Move m2);
// we simply create and use a standard MovePicker object.
template<bool SpNode> struct MovePickerExt : public MovePicker {
- MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
+ 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<true> : public MovePicker {
- MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, SearchStack* ss, Value b)
+ 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 get_next_move() { return mp->get_next_move(); }
Move id_loop(Position& pos, Move rootMoves[], Move* ponderMove) {
- SearchStack ss[PLY_MAX_PLUS_2];
+ Stack ss[PLY_MAX_PLUS_2];
Value bestValues[PLY_MAX_PLUS_2];
int bestMoveChanges[PLY_MAX_PLUS_2];
int depth, aspirationDelta;
bool bestMoveNeverChanged = true;
// Initialize stuff before a new search
- memset(ss, 0, 4 * sizeof(SearchStack));
+ memset(ss, 0, 4 * sizeof(Stack));
TT.new_search();
H.clear();
*ponderMove = bestMove = skillBest = skillPonder = MOVE_NONE;
// here: This is taken care of after we return from the split point.
template <NodeType NT>
- Value search(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth) {
+ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
const bool PvNode = (NT == PV || NT == Root || NT == SplitPointPV || NT == SplitPointRoot);
const bool SpNode = (NT == SplitPointPV || NT == SplitPointNonPV || NT == SplitPointRoot);
// less than ONE_PLY).
template <NodeType NT>
- Value qsearch(Position& pos, SearchStack* ss, Value alpha, Value beta, Depth depth) {
+ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
const bool PvNode = (NT == PV);
assert(!do_terminate);
// Copy split point position and search stack and call search()
- SearchStack ss[PLY_MAX_PLUS_2];
+ Stack ss[PLY_MAX_PLUS_2];
SplitPoint* tsp = splitPoint;
Position pos(*tsp->pos, threadID);
- memcpy(ss, tsp->ss - 1, 4 * sizeof(SearchStack));
+ memcpy(ss, tsp->ss - 1, 4 * sizeof(Stack));
(ss+1)->sp = tsp;
if (tsp->nodeType == Root)
class Position;
struct SplitPoint;
-/// The SearchStack struct keeps track of the information we need to remember
-/// from nodes shallower and deeper in the tree during the search. Each
-/// search thread has its own array of SearchStack objects, indexed by the
-/// current ply.
+namespace Search {
+
+/// The Stack struct keeps track of the information we need to remember from
+/// nodes shallower and deeper in the tree during the search. Each search thread
+/// has its own array of Stack objects, indexed by the current ply.
-struct SearchStack {
+struct Stack {
SplitPoint* sp;
int ply;
Move currentMove;
int skipNullMove;
};
-namespace Search {
-/// The SearchLimits struct stores information sent by GUI about available time
+/// The LimitsType struct stores information sent by GUI about available time
/// to search the current move, maximum depth/time, if we are in analysis mode
/// or if we have to ponder while is our opponent's side to move.
int time, increment, movesToGo, maxTime, maxDepth, maxNodes, infinite, ponder;
};
+
+/// The SignalsType struct stores volatile flags updated during the search
+/// typically in an async fashion, for instance to stop the search by the GUI.
+
struct SignalsType {
bool stopOnPonderhit, firstRootMove, stop, failedLowAtRoot;
};
} // namespace
-extern void do_timer_event();
-
#endif // !defined(SEARCH_H_INCLUDED)
#include "thread.h"
#include "ucioption.h"
+using namespace Search;
+
ThreadsManager Threads; // Global object
namespace { extern "C" {
// search(). When all threads have returned from search() then split() returns.
template <bool Fake>
-Value ThreadsManager::split(Position& pos, SearchStack* ss, Value alpha, Value beta,
+Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta,
Value bestValue, Depth depth, Move threatMove,
int moveCount, MovePicker* mp, int nodeType) {
assert(pos.pos_is_ok());
}
// Explicit template instantiations
-template Value ThreadsManager::split<false>(Position&, SearchStack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
-template Value ThreadsManager::split<true>(Position&, SearchStack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
+template Value ThreadsManager::split<false>(Position&, Stack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
+template Value ThreadsManager::split<true>(Position&, Stack*, Value, Value, Value, Depth, Move, int, MovePicker*, int);
// Thread::timer_loop() is where the timer thread waits maxPly milliseconds and
// then calls do_timer_event(). If maxPly is 0 thread sleeps until is woken up.
+extern void do_timer_event();
void Thread::timer_loop() {
if (do_terminate)
return;
- Search::think(); // This is the search entry point
+ think(); // This is the search entry point
}
}
// then function returns immediately, otherwise caller is blocked waiting for
// the search to finish.
-void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsType& limits,
+void ThreadsManager::start_thinking(const Position& pos, const LimitsType& limits,
const std::vector<Move>& searchMoves, bool asyncMode) {
Thread& main = threads[0];
cond_wait(&sleepCond, &main.sleepLock);
// Copy input arguments to initialize the search
- Search::RootPosition.copy(pos, 0);
- Search::Limits = limits;
- Search::RootMoves = searchMoves;
+ RootPosition.copy(pos, 0);
+ Limits = limits;
+ RootMoves = searchMoves;
// Reset signals before to start the new search
- memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
+ memset((void*)&Signals, 0, sizeof(Signals));
main.do_sleep = false;
cond_signal(&main.sleepCond); // Wake up main thread and start searching
void ThreadsManager::wait_for_stop_or_ponderhit() {
- Search::Signals.stopOnPonderhit = true;
+ Signals.stopOnPonderhit = true;
Thread& main = threads[0];
lock_grab(&main.sleepLock);
- while (!Search::Signals.stop)
+ while (!Signals.stop)
cond_wait(&main.sleepCond, &main.sleepLock);
lock_release(&main.sleepLock);
// Const pointers to shared data
MovePicker* mp;
- SearchStack* ss;
+ Search::Stack* ss;
// Shared data
Lock lock;
const std::vector<Move>& searchMoves, bool asyncMode);
template <bool Fake>
- Value split(Position& pos, SearchStack* ss, Value alpha, Value beta, Value bestValue,
+ Value split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value bestValue,
Depth depth, Move threatMove, int moveCount, MovePicker* mp, int nodeType);
private:
friend struct Thread;