mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Move SearchStack under Search namespace
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
81cd417b45
commit
5b8ca1eee7
6 changed files with 45 additions and 42 deletions
|
@ -72,7 +72,7 @@ namespace {
|
||||||
/// move ordering is at the current node.
|
/// move ordering is at the current node.
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
|
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;
|
captureThreshold = 0;
|
||||||
badCaptures = moves + MAX_MOVES;
|
badCaptures = moves + MAX_MOVES;
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,9 @@
|
||||||
|
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
#include "search.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
struct SearchStack;
|
|
||||||
|
|
||||||
/// MovePicker is a class which is used to pick one pseudo legal move at a time
|
/// 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
|
/// 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
|
/// 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
|
MovePicker& operator=(const MovePicker&); // Silence a warning under MSVC
|
||||||
|
|
||||||
public:
|
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, Depth, const History&, Square recaptureSq);
|
||||||
MovePicker(const Position&, Move, const History&, PieceType parentCapture);
|
MovePicker(const Position&, Move, const History&, PieceType parentCapture);
|
||||||
Move get_next_move();
|
Move get_next_move();
|
||||||
|
|
|
@ -38,12 +38,6 @@
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
using Search::Signals;
|
|
||||||
using Search::Limits;
|
|
||||||
|
|
||||||
namespace Search {
|
namespace Search {
|
||||||
|
|
||||||
volatile SignalsType Signals;
|
volatile SignalsType Signals;
|
||||||
|
@ -52,6 +46,11 @@ namespace Search {
|
||||||
Position RootPosition;
|
Position RootPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::string;
|
||||||
|
using namespace Search;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Set to true to force running with one thread. Used for debugging
|
// 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);
|
Move id_loop(Position& pos, Move rootMoves[], Move* ponderMove);
|
||||||
|
|
||||||
template <NodeType NT>
|
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>
|
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 check_is_dangerous(Position &pos, Move move, Value futilityBase, Value beta, Value *bValue);
|
||||||
bool connected_moves(const Position& pos, Move m1, Move m2);
|
bool connected_moves(const Position& pos, Move m1, Move m2);
|
||||||
|
@ -213,14 +212,14 @@ namespace {
|
||||||
// we simply create and use a standard MovePicker object.
|
// we simply create and use a standard MovePicker object.
|
||||||
template<bool SpNode> struct MovePickerExt : public MovePicker {
|
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) {}
|
: MovePicker(p, ttm, d, h, ss, b) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// In case of a SpNode we use split point's shared MovePicker object as moves source
|
// In case of a SpNode we use split point's shared MovePicker object as moves source
|
||||||
template<> struct MovePickerExt<true> : public MovePicker {
|
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) {}
|
: MovePicker(p, ttm, d, h, ss, b), mp(ss->sp->mp) {}
|
||||||
|
|
||||||
Move get_next_move() { return mp->get_next_move(); }
|
Move get_next_move() { return mp->get_next_move(); }
|
||||||
|
@ -487,7 +486,7 @@ namespace {
|
||||||
|
|
||||||
Move id_loop(Position& pos, Move rootMoves[], Move* ponderMove) {
|
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];
|
Value bestValues[PLY_MAX_PLUS_2];
|
||||||
int bestMoveChanges[PLY_MAX_PLUS_2];
|
int bestMoveChanges[PLY_MAX_PLUS_2];
|
||||||
int depth, aspirationDelta;
|
int depth, aspirationDelta;
|
||||||
|
@ -496,7 +495,7 @@ namespace {
|
||||||
bool bestMoveNeverChanged = true;
|
bool bestMoveNeverChanged = true;
|
||||||
|
|
||||||
// Initialize stuff before a new search
|
// Initialize stuff before a new search
|
||||||
memset(ss, 0, 4 * sizeof(SearchStack));
|
memset(ss, 0, 4 * sizeof(Stack));
|
||||||
TT.new_search();
|
TT.new_search();
|
||||||
H.clear();
|
H.clear();
|
||||||
*ponderMove = bestMove = skillBest = skillPonder = MOVE_NONE;
|
*ponderMove = bestMove = skillBest = skillPonder = MOVE_NONE;
|
||||||
|
@ -708,7 +707,7 @@ namespace {
|
||||||
// here: This is taken care of after we return from the split point.
|
// here: This is taken care of after we return from the split point.
|
||||||
|
|
||||||
template <NodeType NT>
|
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 PvNode = (NT == PV || NT == Root || NT == SplitPointPV || NT == SplitPointRoot);
|
||||||
const bool SpNode = (NT == SplitPointPV || NT == SplitPointNonPV || 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).
|
// less than ONE_PLY).
|
||||||
|
|
||||||
template <NodeType NT>
|
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);
|
const bool PvNode = (NT == PV);
|
||||||
|
|
||||||
|
@ -2101,11 +2100,11 @@ void Thread::idle_loop(SplitPoint* sp) {
|
||||||
assert(!do_terminate);
|
assert(!do_terminate);
|
||||||
|
|
||||||
// Copy split point position and search stack and call search()
|
// 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;
|
SplitPoint* tsp = splitPoint;
|
||||||
Position pos(*tsp->pos, threadID);
|
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;
|
(ss+1)->sp = tsp;
|
||||||
|
|
||||||
if (tsp->nodeType == Root)
|
if (tsp->nodeType == Root)
|
||||||
|
|
20
src/search.h
20
src/search.h
|
@ -28,12 +28,13 @@
|
||||||
class Position;
|
class Position;
|
||||||
struct SplitPoint;
|
struct SplitPoint;
|
||||||
|
|
||||||
/// The SearchStack struct keeps track of the information we need to remember
|
namespace Search {
|
||||||
/// 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.
|
|
||||||
|
|
||||||
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;
|
SplitPoint* sp;
|
||||||
int ply;
|
int ply;
|
||||||
Move currentMove;
|
Move currentMove;
|
||||||
|
@ -46,9 +47,8 @@ struct SearchStack {
|
||||||
int skipNullMove;
|
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
|
/// 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.
|
/// 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;
|
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 {
|
struct SignalsType {
|
||||||
bool stopOnPonderhit, firstRootMove, stop, failedLowAtRoot;
|
bool stopOnPonderhit, firstRootMove, stop, failedLowAtRoot;
|
||||||
};
|
};
|
||||||
|
@ -75,6 +79,4 @@ extern void think();
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern void do_timer_event();
|
|
||||||
|
|
||||||
#endif // !defined(SEARCH_H_INCLUDED)
|
#endif // !defined(SEARCH_H_INCLUDED)
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
|
||||||
|
using namespace Search;
|
||||||
|
|
||||||
ThreadsManager Threads; // Global object
|
ThreadsManager Threads; // Global object
|
||||||
|
|
||||||
namespace { extern "C" {
|
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.
|
// search(). When all threads have returned from search() then split() returns.
|
||||||
|
|
||||||
template <bool Fake>
|
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,
|
Value bestValue, Depth depth, Move threatMove,
|
||||||
int moveCount, MovePicker* mp, int nodeType) {
|
int moveCount, MovePicker* mp, int nodeType) {
|
||||||
assert(pos.pos_is_ok());
|
assert(pos.pos_is_ok());
|
||||||
|
@ -359,12 +361,13 @@ Value ThreadsManager::split(Position& pos, SearchStack* ss, Value alpha, Value b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit template instantiations
|
// Explicit template instantiations
|
||||||
template Value ThreadsManager::split<false>(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&, SearchStack*, 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
|
// 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.
|
// then calls do_timer_event(). If maxPly is 0 thread sleeps until is woken up.
|
||||||
|
extern void do_timer_event();
|
||||||
|
|
||||||
void Thread::timer_loop() {
|
void Thread::timer_loop() {
|
||||||
|
|
||||||
|
@ -417,7 +420,7 @@ void Thread::main_loop() {
|
||||||
if (do_terminate)
|
if (do_terminate)
|
||||||
return;
|
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
|
// then function returns immediately, otherwise caller is blocked waiting for
|
||||||
// the search to finish.
|
// 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) {
|
const std::vector<Move>& searchMoves, bool asyncMode) {
|
||||||
Thread& main = threads[0];
|
Thread& main = threads[0];
|
||||||
|
|
||||||
|
@ -438,12 +441,12 @@ void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsTyp
|
||||||
cond_wait(&sleepCond, &main.sleepLock);
|
cond_wait(&sleepCond, &main.sleepLock);
|
||||||
|
|
||||||
// Copy input arguments to initialize the search
|
// Copy input arguments to initialize the search
|
||||||
Search::RootPosition.copy(pos, 0);
|
RootPosition.copy(pos, 0);
|
||||||
Search::Limits = limits;
|
Limits = limits;
|
||||||
Search::RootMoves = searchMoves;
|
RootMoves = searchMoves;
|
||||||
|
|
||||||
// Reset signals before to start the new search
|
// 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;
|
main.do_sleep = false;
|
||||||
cond_signal(&main.sleepCond); // Wake up main thread and start searching
|
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() {
|
void ThreadsManager::wait_for_stop_or_ponderhit() {
|
||||||
|
|
||||||
Search::Signals.stopOnPonderhit = true;
|
Signals.stopOnPonderhit = true;
|
||||||
|
|
||||||
Thread& main = threads[0];
|
Thread& main = threads[0];
|
||||||
|
|
||||||
lock_grab(&main.sleepLock);
|
lock_grab(&main.sleepLock);
|
||||||
|
|
||||||
while (!Search::Signals.stop)
|
while (!Signals.stop)
|
||||||
cond_wait(&main.sleepCond, &main.sleepLock);
|
cond_wait(&main.sleepCond, &main.sleepLock);
|
||||||
|
|
||||||
lock_release(&main.sleepLock);
|
lock_release(&main.sleepLock);
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct SplitPoint {
|
||||||
|
|
||||||
// Const pointers to shared data
|
// Const pointers to shared data
|
||||||
MovePicker* mp;
|
MovePicker* mp;
|
||||||
SearchStack* ss;
|
Search::Stack* ss;
|
||||||
|
|
||||||
// Shared data
|
// Shared data
|
||||||
Lock lock;
|
Lock lock;
|
||||||
|
@ -122,7 +122,7 @@ public:
|
||||||
const std::vector<Move>& searchMoves, bool asyncMode);
|
const std::vector<Move>& searchMoves, bool asyncMode);
|
||||||
|
|
||||||
template <bool Fake>
|
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);
|
Depth depth, Move threatMove, int moveCount, MovePicker* mp, int nodeType);
|
||||||
private:
|
private:
|
||||||
friend struct Thread;
|
friend struct Thread;
|
||||||
|
|
Loading…
Add table
Reference in a new issue