HASH: 哈希表扩大到128M

效率看不出差异
This commit is contained in:
CalciteM Team 2019-07-14 21:45:35 +08:00
parent ecebd39347
commit e4ea2851c2
1 changed files with 29 additions and 28 deletions

View File

@ -18,7 +18,7 @@
using namespace CTSL;
#ifdef HASH_MAP_ENABLE
static constexpr int hashsize = 0x1000000; // 16M
static constexpr int hashsize = 0x8000000; // 128M
HashMap<uint64_t, NineChessAi_ab::HashValue> hashmap(hashsize);
#endif
@ -622,6 +622,10 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
// 哈希类型
enum HashType hashf = hashfALPHA;
// 获取哈希值
uint64_t hash = chessTemp.getHash();
node->hash = hash;
#endif
#ifdef DEBUG_AB_TREE
@ -638,15 +642,35 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
#endif // HASH_MAP_ENABLE
#endif // DEBUG_AB_TREE
// 搜索到叶子节点(决胜局面)
if (chessContext->stage == NineChess::GAME_OVER) {
// 局面评估
node->value = evaluate(node);
// 为争取速胜value 值 +- 深度
if (node->value > 0)
node->value += depth;
else
node->value -= depth;
#ifdef DEBUG_AB_TREE
node->isLeaf = true;
#endif
#ifdef HASH_MAP_ENABLE
// 记录确切的哈希值
recordHash(node->value, alpha, beta, depth, hashfEXACT, hash);
#endif
return node->value;
}
#ifdef HASH_MAP_ENABLE
// 检索 hashmap
uint64_t hash = chessTemp.getHash();
node->hash = hash;
//hashMapMutex.lock();
// 从地址里一定可以读取出东西found 恒定为 true?
bool found = findHash(hash, hashValue);
bool found = findHash(hash, hashValue);
if (node != rootNode &&
hashValue.hash == hash && // 校验放在这里?
@ -673,29 +697,6 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
//hashMapMutex.unlock();
#endif /* HASH_MAP_ENABLE */
// 搜索到叶子节点(决胜局面)
if (chessContext->stage == NineChess::GAME_OVER) {
// 局面评估
node->value = evaluate(node);
// 为争取速胜value 值 +- 深度
if (node->value > 0)
node->value += depth;
else
node->value -= depth;
#ifdef DEBUG_AB_TREE
node->isLeaf = true;
#endif
#ifdef HASH_MAP_ENABLE
// 记录确切的哈希值
recordHash(node->value, alpha, beta, depth, hashfEXACT, hash);
#endif
return node->value;
}
// 搜索到第0层或需要退出
if (!depth || requiredQuit) {
// 局面评估