不搜索翻转局面的HASH

This commit is contained in:
CalciteM 2019-07-07 12:59:07 +08:00
parent 86688629d7
commit c55b10b129
3 changed files with 13 additions and 11 deletions

View File

@ -1,7 +1,7 @@
#ifndef CONFIG_H
#define CONFIG_H
#define DEBUG
//#define DEBUG
//#define DEAL_WITH_HORIZON_EFFECT
@ -42,7 +42,7 @@
#define DRAW_SEAT_NUMBER
#endif
//#define IDS_SUPPORT
#define IDS_SUPPORT
#define SAVE_CHESSBOOK_WHEN_ACTION_NEW_TRIGGERED

View File

@ -63,6 +63,7 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(Node *parent, int value, in
newNode->alpha = -INF_VALUE;
newNode->beta = INF_VALUE;
newNode->result = 0;
newNode->isHash = false;
#endif
int c, p;
char cmd[32] = { 0 };
@ -701,12 +702,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
}
// 更新更深层数据
else {
hashMapMutex.lock();
if (iter->second.depth < depth) {
//hashMapMutex.lock();
//if (iter->second.depth < depth) {
//iter->second.value = node->value;
//iter->second.depth = depth;
}
hashMapMutex.unlock();
//}
//hashMapMutex.unlock();
}
#endif
@ -763,9 +764,9 @@ const char* NineChessAi_ab::bestMove()
string moves = "";
for (auto child : rootNode->children) {
if (child->value == rootNode->value)
qDebug("[%.2d] %d\t%s\t%d *", i, child->move, move2string(child->move), child->value);
qDebug("[%.2d] %d\t%s\t%d H%d *", i, child->move, move2string(child->move), child->value, child->isHash);
else
qDebug("[%.2d] %d\t%s\t%d", i, child->move, move2string(child->move), child->value);
qDebug("[%.2d] %d\t%s\t%d H%d", i, child->move, move2string(child->move), child->value, child->isHash);
i++;
}
@ -835,6 +836,7 @@ unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator NineChessAi_ab::fin
{
auto iter = hashmap.find(hash);
#if 0
if (iter != hashmap.end())
return iter;
@ -855,6 +857,7 @@ unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator NineChessAi_ab::fin
}
}
}
#endif
return iter;
}

View File

@ -52,9 +52,8 @@ public:
struct Node* parent; // 父节点
size_t id; // 结点编号
int rand; // 随机数,对于 value 一致的结点随机排序用
#ifdef HASH_MAP_ENABLE
uint64_t hash;
#endif
bool isHash; // 是否从 Hash 读取
#ifdef DEBUG_AB_TREE
string cmd;
enum NineChess::Player player; // 此招是谁下的
@ -64,7 +63,7 @@ public:
int beta; // 表示对手目前的劣势这是对手所能承受的最坏结果Beta 值越大,表示对手劣势越明显,如果当前结点返回 Beta 或比 Beta 更好的值,作为父结点的对方就绝对不会选择这种策略
bool isTimeout; // 是否遍历到此结点时因为超时而被迫退出
bool isLeaf; // 是否为叶子结点, 叶子结点是决胜局面
bool isHash; // 是否从 Hash 读取
NineChess::GameStage stage; // 摆棋阶段还是走棋阶段
NineChess::Action action; // 动作状态
int nPiecesOnBoardDiff; // 场上棋子个数和对手的差值