1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Move SearchStack under Search namespace

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-12-04 11:46:31 +01:00
parent 81cd417b45
commit 5b8ca1eee7
6 changed files with 45 additions and 42 deletions

View file

@ -72,7 +72,7 @@ namespace {
/// 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;

View file

@ -22,10 +22,9 @@
#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
@ -39,7 +38,7 @@ class MovePicker {
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();

View file

@ -38,12 +38,6 @@
#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;
@ -52,6 +46,11 @@ namespace Search {
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
@ -186,10 +185,10 @@ namespace {
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);
@ -213,14 +212,14 @@ namespace {
// 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(); }
@ -487,7 +486,7 @@ namespace {
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;
@ -496,7 +495,7 @@ namespace {
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;
@ -708,7 +707,7 @@ namespace {
// 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);
@ -1297,7 +1296,7 @@ split_point_start: // At split points actual search starts from here
// 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);
@ -2101,11 +2100,11 @@ void Thread::idle_loop(SplitPoint* sp) {
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)

View file

@ -28,12 +28,13 @@
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 {
struct SearchStack {
/// 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 Stack {
SplitPoint* sp;
int ply;
Move currentMove;
@ -46,9 +47,8 @@ struct SearchStack {
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.
@ -60,6 +60,10 @@ struct LimitsType {
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;
};
@ -75,6 +79,4 @@ extern void think();
} // namespace
extern void do_timer_event();
#endif // !defined(SEARCH_H_INCLUDED)

View file

@ -23,6 +23,8 @@
#include "thread.h"
#include "ucioption.h"
using namespace Search;
ThreadsManager Threads; // Global object
namespace { extern "C" {
@ -257,7 +259,7 @@ bool ThreadsManager::split_point_finished(SplitPoint* sp) const {
// 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());
@ -359,12 +361,13 @@ Value ThreadsManager::split(Position& pos, SearchStack* ss, Value alpha, Value b
}
// 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() {
@ -417,7 +420,7 @@ void Thread::main_loop() {
if (do_terminate)
return;
Search::think(); // This is the search entry point
think(); // This is the search entry point
}
}
@ -427,7 +430,7 @@ void Thread::main_loop() {
// 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];
@ -438,12 +441,12 @@ void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsTyp
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
@ -464,13 +467,13 @@ void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsTyp
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);

View file

@ -46,7 +46,7 @@ struct SplitPoint {
// Const pointers to shared data
MovePicker* mp;
SearchStack* ss;
Search::Stack* ss;
// Shared data
Lock lock;
@ -122,7 +122,7 @@ public:
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;