增加 recordHash()
This commit is contained in:
parent
4d72e101d2
commit
42f6b5d0d2
|
@ -680,23 +680,19 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HASH_MAP_ENABLE
|
#ifdef HASH_MAP_ENABLE
|
||||||
// 添加到hashmap
|
|
||||||
hashMapMutex.lock();
|
|
||||||
if (iter == hashmap.end()) {
|
if (iter == hashmap.end()) {
|
||||||
HashValue hashValue;
|
// 添加到hashmap
|
||||||
hashValue.value = node->value;
|
recordHash(hash, depth, node->value, hashfEMPTY);
|
||||||
hashValue.depth = depth;
|
|
||||||
if (hashmap.size() <= maxHashCount)
|
|
||||||
hashmap.insert({hash, hashValue});
|
|
||||||
}
|
}
|
||||||
// 更新更深层数据
|
// 更新更深层数据
|
||||||
else {
|
else {
|
||||||
|
hashMapMutex.lock();
|
||||||
if (iter->second.depth < depth) {
|
if (iter->second.depth < depth) {
|
||||||
iter->second.value = node->value;
|
iter->second.value = node->value;
|
||||||
iter->second.depth = depth;
|
iter->second.depth = depth;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
hashMapMutex.unlock();
|
hashMapMutex.unlock();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 排序子节点树
|
// 排序子节点树
|
||||||
|
@ -706,6 +702,23 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
||||||
return node->value;
|
return node->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int NineChessAi_ab::recordHash(uint64_t hash, int16_t depth, int value, enum HashType type)
|
||||||
|
{
|
||||||
|
#ifdef HASH_MAP_ENABLE
|
||||||
|
hashMapMutex.lock();
|
||||||
|
|
||||||
|
HashValue hashValue;
|
||||||
|
hashValue.value = value;
|
||||||
|
hashValue.depth = depth;
|
||||||
|
if (hashmap.size() <= maxHashCount)
|
||||||
|
hashmap.insert({ hash, hashValue });
|
||||||
|
|
||||||
|
hashMapMutex.unlock();
|
||||||
|
#endif // HASH_MAP_ENABLE
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const char* NineChessAi_ab::bestMove()
|
const char* NineChessAi_ab::bestMove()
|
||||||
{
|
{
|
||||||
vector<Node*> bestMoves;
|
vector<Node*> bestMoves;
|
||||||
|
|
|
@ -27,7 +27,7 @@ class NineChessAi_ab
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// 定义哈希值的类型
|
// 定义哈希值的类型
|
||||||
enum hashType : int16_t
|
enum HashType : int16_t
|
||||||
{
|
{
|
||||||
hashfEMPTY = 0,
|
hashfEMPTY = 0,
|
||||||
hashfALPHA = 1,
|
hashfALPHA = 1,
|
||||||
|
@ -112,6 +112,9 @@ protected:
|
||||||
// 增加新节点
|
// 增加新节点
|
||||||
struct Node *addNode(Node *parent, int value, NineChess::move_t move, enum NineChess::Player player);
|
struct Node *addNode(Node *parent, int value, NineChess::move_t move, enum NineChess::Player player);
|
||||||
|
|
||||||
|
// 插入哈希表
|
||||||
|
int recordHash(uint64_t hash, int16_t depth, int value, enum HashType type);
|
||||||
|
|
||||||
// 评价函数
|
// 评价函数
|
||||||
int evaluate(Node *node);
|
int evaluate(Node *node);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue