增加 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
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
// 添加到hashmap
|
||||
hashMapMutex.lock();
|
||||
if (iter == hashmap.end()) {
|
||||
HashValue hashValue;
|
||||
hashValue.value = node->value;
|
||||
hashValue.depth = depth;
|
||||
if (hashmap.size() <= maxHashCount)
|
||||
hashmap.insert({hash, hashValue});
|
||||
// 添加到hashmap
|
||||
recordHash(hash, depth, node->value, hashfEMPTY);
|
||||
}
|
||||
// 更新更深层数据
|
||||
else {
|
||||
hashMapMutex.lock();
|
||||
if (iter->second.depth < depth) {
|
||||
iter->second.value = node->value;
|
||||
iter->second.depth = depth;
|
||||
}
|
||||
hashMapMutex.unlock();
|
||||
}
|
||||
hashMapMutex.unlock();
|
||||
#endif
|
||||
|
||||
// 排序子节点树
|
||||
|
@ -706,6 +702,23 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
|||
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()
|
||||
{
|
||||
vector<Node*> bestMoves;
|
||||
|
|
|
@ -27,7 +27,7 @@ class NineChessAi_ab
|
|||
{
|
||||
public:
|
||||
// 定义哈希值的类型
|
||||
enum hashType : int16_t
|
||||
enum HashType : int16_t
|
||||
{
|
||||
hashfEMPTY = 0,
|
||||
hashfALPHA = 1,
|
||||
|
@ -112,6 +112,9 @@ protected:
|
|||
// 增加新节点
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue