将搜索哈希放在叶子结点处理流程之前
This commit is contained in:
parent
d38200dce5
commit
4d72e101d2
|
@ -42,7 +42,7 @@
|
||||||
#define DRAW_SEAT_NUMBER
|
#define DRAW_SEAT_NUMBER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IDS_SUPPORT
|
//#define IDS_SUPPORT
|
||||||
|
|
||||||
#define SAVE_CHESSBOOK_WHEN_ACTION_NEW_TRIGGERED
|
#define SAVE_CHESSBOOK_WHEN_ACTION_NEW_TRIGGERED
|
||||||
|
|
||||||
|
|
|
@ -517,45 +517,9 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
||||||
node->isLeaf = false;
|
node->isLeaf = false;
|
||||||
node->isTimeout = false;
|
node->isTimeout = false;
|
||||||
node->isHash = false;
|
node->isHash = false;
|
||||||
|
node->hash = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 搜索到叶子节点(决胜局面)
|
|
||||||
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
|
|
||||||
|
|
||||||
return node->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 搜索到第0层或需要退出
|
|
||||||
if (!depth || requiredQuit) {
|
|
||||||
// 局面评估
|
|
||||||
node->value = evaluate(node);
|
|
||||||
|
|
||||||
// 为争取速胜,value 值 +- 深度
|
|
||||||
if (chessContext->turn == NineChess::PLAYER1)
|
|
||||||
node->value += depth;
|
|
||||||
else
|
|
||||||
node->value -= depth;
|
|
||||||
|
|
||||||
#ifdef DEBUG_AB_TREE
|
|
||||||
if (requiredQuit) {
|
|
||||||
node->isTimeout = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return node->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HASH_MAP_ENABLE
|
#ifdef HASH_MAP_ENABLE
|
||||||
// 检索 hashmap
|
// 检索 hashmap
|
||||||
uint64_t hash = chessTemp.getHash();
|
uint64_t hash = chessTemp.getHash();
|
||||||
|
@ -589,6 +553,48 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
|
||||||
hashMapMutex.unlock();
|
hashMapMutex.unlock();
|
||||||
#endif /* HASH_MAP_ENABLE */
|
#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
|
||||||
|
|
||||||
|
// TODO: RecordHash
|
||||||
|
|
||||||
|
return node->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索到第0层或需要退出
|
||||||
|
if (!depth || requiredQuit) {
|
||||||
|
// 局面评估
|
||||||
|
node->value = evaluate(node);
|
||||||
|
|
||||||
|
// 为争取速胜,value 值 +- 深度
|
||||||
|
if (chessContext->turn == NineChess::PLAYER1)
|
||||||
|
node->value += depth;
|
||||||
|
else
|
||||||
|
node->value -= depth;
|
||||||
|
|
||||||
|
#ifdef DEBUG_AB_TREE
|
||||||
|
if (requiredQuit) {
|
||||||
|
node->isTimeout = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TODO: RecordHash
|
||||||
|
|
||||||
|
return node->value;
|
||||||
|
}
|
||||||
|
|
||||||
// 生成子节点树,即生成每个合理的着法
|
// 生成子节点树,即生成每个合理的着法
|
||||||
generateLegalMoves(node);
|
generateLegalMoves(node);
|
||||||
|
|
||||||
|
@ -818,5 +824,6 @@ unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator NineChessAi_ab::fin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,21 @@ using namespace std;
|
||||||
class NineChessAi_ab
|
class NineChessAi_ab
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// 定义哈希值的类型
|
||||||
|
enum hashType : int16_t
|
||||||
|
{
|
||||||
|
hashfEMPTY = 0,
|
||||||
|
hashfALPHA = 1,
|
||||||
|
hashfBETA = 2,
|
||||||
|
hashfEXACT = 3
|
||||||
|
};
|
||||||
|
|
||||||
// 定义哈希表的值
|
// 定义哈希表的值
|
||||||
struct HashValue
|
struct HashValue
|
||||||
{
|
{
|
||||||
int16_t value;
|
int16_t value;
|
||||||
int16_t depth;
|
int16_t depth;
|
||||||
|
enum hashType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 定义一个节点结构体
|
// 定义一个节点结构体
|
||||||
|
@ -156,8 +166,11 @@ private:
|
||||||
// 哈希表的默认大小
|
// 哈希表的默认大小
|
||||||
static const size_t maxHashCount = 1024 * 1024;
|
static const size_t maxHashCount = 1024 * 1024;
|
||||||
|
|
||||||
// 定义极大值,等于16位有符号整形数字的最大值
|
// 定义极大值
|
||||||
static const int INF_VALUE = INT32_MAX;
|
static const int INF_VALUE = 0x1 << 30;
|
||||||
|
|
||||||
|
// 定义未知值
|
||||||
|
static const int UNKNOWN_VALUE = INT32_MAX;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 命令行
|
// 命令行
|
||||||
|
|
Loading…
Reference in New Issue