search: refactor: 增加了一些暂时用不到的代码
This commit is contained in:
parent
e6e336aa3b
commit
8a40b48f93
|
@ -35,23 +35,103 @@
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#include "hashmap.h"
|
|
||||||
#include "endgame.h"
|
#include "endgame.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "option.h"
|
#include "option.h"
|
||||||
|
|
||||||
using namespace CTSL;
|
|
||||||
|
|
||||||
namespace Search
|
namespace Search
|
||||||
{
|
{
|
||||||
LimitsType Limits;
|
LimitsType Limits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using Eval::evaluate;
|
||||||
using namespace Search;
|
using namespace Search;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// Different node types, used as a template parameter
|
||||||
|
enum NodeType
|
||||||
|
{
|
||||||
|
NonPV, PV
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add a small random component to draw evaluations to avoid 3fold-blindness
|
||||||
|
Value value_draw(Thread *thisThread)
|
||||||
|
{
|
||||||
|
return VALUE_DRAW + Value(2 * (thisThread->nodes & 1) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skill structure is used to implement strength limit
|
||||||
|
struct Skill
|
||||||
|
{
|
||||||
|
explicit Skill(int l) : level(l)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
bool enabled() const
|
||||||
|
{
|
||||||
|
return level < 20;
|
||||||
|
}
|
||||||
|
bool time_to_pick(Depth depth) const
|
||||||
|
{
|
||||||
|
return depth == 1 + level;
|
||||||
|
}
|
||||||
|
Move pick_best(size_t multiPV);
|
||||||
|
|
||||||
|
int level;
|
||||||
|
Move best = MOVE_NONE;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Breadcrumbs are used to mark nodes as being searched by a given thread
|
||||||
|
struct Breadcrumb
|
||||||
|
{
|
||||||
|
std::atomic<Thread *> thread;
|
||||||
|
std::atomic<Key> key;
|
||||||
|
};
|
||||||
|
std::array<Breadcrumb, 1024> breadcrumbs;
|
||||||
|
|
||||||
|
// ThreadHolding structure keeps track of which thread left breadcrumbs at the given
|
||||||
|
// node for potential reductions. A free node will be marked upon entering the moves
|
||||||
|
// loop by the constructor, and unmarked upon leaving that loop by the destructor.
|
||||||
|
struct ThreadHolding
|
||||||
|
{
|
||||||
|
explicit ThreadHolding(Thread *thisThread, Key posKey, int ply)
|
||||||
|
{
|
||||||
|
location = ply < 8 ? &breadcrumbs[posKey & (breadcrumbs.size() - 1)] : nullptr;
|
||||||
|
otherThread = false;
|
||||||
|
owning = false;
|
||||||
|
if (location) {
|
||||||
|
// See if another already marked this location, if not, mark it ourselves
|
||||||
|
Thread *tmp = (*location).thread.load(std::memory_order_relaxed);
|
||||||
|
if (tmp == nullptr) {
|
||||||
|
(*location).thread.store(thisThread, std::memory_order_relaxed);
|
||||||
|
(*location).key.store(posKey, std::memory_order_relaxed);
|
||||||
|
owning = true;
|
||||||
|
} else if (tmp != thisThread
|
||||||
|
&& (*location).key.load(std::memory_order_relaxed) == posKey)
|
||||||
|
otherThread = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~ThreadHolding()
|
||||||
|
{
|
||||||
|
if (owning) // Free the marked location
|
||||||
|
(*location).thread.store(nullptr, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool marked()
|
||||||
|
{
|
||||||
|
return otherThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Breadcrumb *location;
|
||||||
|
bool otherThread, owning;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Value MTDF(Position *pos, Stack<Position> &ss, Value firstguess, Depth depth, Depth originDepth, Move &bestMove);
|
Value MTDF(Position *pos, Stack<Position> &ss, Value firstguess, Depth depth, Depth originDepth, Move &bestMove);
|
||||||
|
|
||||||
vector<Key> moveHistory;
|
vector<Key> moveHistory;
|
||||||
|
|
24
src/search.h
24
src/search.h
|
@ -17,21 +17,13 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SEARCH_H
|
#ifndef SEARCH_H_INCLUDED
|
||||||
#define SEARCH_H
|
#define SEARCH_H_INCLUDED
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <string>
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "hashmap.h"
|
|
||||||
#include "endgame.h"
|
#include "endgame.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
#ifdef CYCLE_STAT
|
#ifdef CYCLE_STAT
|
||||||
#include "stopwatch.h"
|
#include "stopwatch.h"
|
||||||
|
@ -50,7 +42,6 @@ namespace Search
|
||||||
/// Threshold used for countermoves based pruning
|
/// Threshold used for countermoves based pruning
|
||||||
constexpr int CounterMovePruneThreshold = 0;
|
constexpr int CounterMovePruneThreshold = 0;
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/// Stack struct keeps track of the information we need to remember from nodes
|
/// 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
|
/// shallower and deeper in the tree during the search. Each search thread has
|
||||||
|
@ -70,14 +61,12 @@ struct Stack
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// RootMove struct is used for moves at the root of the tree. For each root move
|
/// RootMove struct is used for moves at the root of the tree. For each root move
|
||||||
/// we store a score and a PV (really a refutation in the case of moves which
|
/// we store a score and a PV (really a refutation in the case of moves which
|
||||||
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
/// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves.
|
||||||
|
|
||||||
struct RootMove
|
struct RootMove
|
||||||
{
|
{
|
||||||
|
|
||||||
explicit RootMove(Move m) : pv(1, m)
|
explicit RootMove(Move m) : pv(1, m)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -109,7 +98,8 @@ typedef std::vector<RootMove> RootMoves;
|
||||||
struct LimitsType
|
struct LimitsType
|
||||||
{
|
{
|
||||||
LimitsType()
|
LimitsType()
|
||||||
{ // Init explicitly due to broken value-initialization of non POD in MSVC
|
{
|
||||||
|
// Init explicitly due to broken value-initialization of non POD in MSVC
|
||||||
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
|
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
|
||||||
movestogo = depth = mate = perft = infinite = 0;
|
movestogo = depth = mate = perft = infinite = 0;
|
||||||
nodes = 0;
|
nodes = 0;
|
||||||
|
@ -130,7 +120,7 @@ extern LimitsType Limits;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void clear();
|
void clear();
|
||||||
}
|
} // namespace Search
|
||||||
|
|
||||||
class AIAlgorithm
|
class AIAlgorithm
|
||||||
{
|
{
|
||||||
|
@ -185,8 +175,6 @@ protected:
|
||||||
Depth changeDepth();
|
Depth changeDepth();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovePicker *movePicker { nullptr };
|
|
||||||
|
|
||||||
Value bestvalue { VALUE_ZERO };
|
Value bestvalue { VALUE_ZERO };
|
||||||
Value lastvalue { VALUE_ZERO };
|
Value lastvalue { VALUE_ZERO };
|
||||||
|
|
||||||
|
@ -224,4 +212,4 @@ public:
|
||||||
extern vector<Key> moveHistory;
|
extern vector<Key> moveHistory;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* SEARCH_H */
|
#endif // #ifndef SEARCH_H_INCLUDED
|
||||||
|
|
Loading…
Reference in New Issue