refactor: 将部分哈希相关重命名为置换表相关名称
This commit is contained in:
parent
3d1022f292
commit
3a043b469c
|
@ -62,12 +62,12 @@
|
|||
|
||||
//define DEEPER_IF_ONLY_ONE_LEGAL_MOVE
|
||||
|
||||
#define HASH_MAP_ENABLE
|
||||
#define TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#define CLEAR_HASH_MAP
|
||||
#define HASH_MAP_CUTDOWN
|
||||
//#define HASH_MAP_DEBUG
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#define CLEAR_TRANSPOSITION_TABLE
|
||||
#define TRANSPOSITION_TABLE_CUTDOWN
|
||||
//#define TRANSPOSITION_TABLE_DEBUG
|
||||
#endif
|
||||
|
||||
#define MEMORY_POOL
|
||||
|
@ -99,13 +99,13 @@
|
|||
#define GAME_MOVING_FIXED_DEPTH 3
|
||||
#else // DEBUG
|
||||
#ifdef DEAL_WITH_HORIZON_EFFECT
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#define GAME_MOVING_FIXED_DEPTH 9
|
||||
#else
|
||||
#define GAME_MOVING_FIXED_DEPTH 9
|
||||
#endif // HASH_MAP_ENABLE
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
#else // DEAL_WITH_HORIZON_EFFECT
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#define GAME_MOVING_FIXED_DEPTH 11
|
||||
#else
|
||||
#define GAME_MOVING_FIXED_DEPTH 10
|
||||
|
|
|
@ -444,6 +444,7 @@
|
|||
<ClInclude Include="src\ai\evaluate.h" />
|
||||
<ClInclude Include="src\ai\movegen.h" />
|
||||
<ClInclude Include="src\ai\search.h" />
|
||||
<ClInclude Include="src\ai\tt.h" />
|
||||
<ClInclude Include="src\ai\zobrist.h" />
|
||||
<ClInclude Include="src\base\debug.h" />
|
||||
<ClInclude Include="src\base\hashmap.h" />
|
||||
|
@ -692,6 +693,7 @@
|
|||
<ClCompile Include="src\ai\evaluate.cpp" />
|
||||
<ClCompile Include="src\ai\movegen.cpp" />
|
||||
<ClCompile Include="src\ai\search.cpp" />
|
||||
<ClCompile Include="src\ai\tt.cpp" />
|
||||
<ClCompile Include="src\base\thread.cpp" />
|
||||
<ClCompile Include="src\game\board.cpp" />
|
||||
<ClCompile Include="src\game\millgame.cpp" />
|
||||
|
|
|
@ -108,6 +108,9 @@
|
|||
<ClInclude Include="src\game\types.h">
|
||||
<Filter>game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ai\tt.h">
|
||||
<Filter>ai</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="debug\moc_predefs.h.cbt">
|
||||
|
@ -314,6 +317,9 @@
|
|||
<ClCompile Include="src\game\rule.cpp">
|
||||
<Filter>game</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ai\tt.cpp">
|
||||
<Filter>ai</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="millgame.rc">
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
|
||||
using namespace CTSL;
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
static constexpr int hashsize = 0x2000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突
|
||||
HashMap<hash_t, MillGameAi_ab::HashValue> hashmap(hashsize);
|
||||
#endif // HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
static constexpr int TRANSPOSITION_TABLE_SIZE = 0x2000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突
|
||||
HashMap<hash_t, MillGameAi_ab::HashValue> transpositionTable(TRANSPOSITION_TABLE_SIZE);
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
#ifdef BOOK_LEARNING
|
||||
static constexpr int bookHashsize = 0x1000000; // 16M
|
||||
|
@ -65,20 +65,20 @@ depth_t MillGameAi_ab::changeDepth(depth_t originalDepth)
|
|||
if ((gameTemp.context.stage) & (GAME_PLACING)) {
|
||||
#ifdef GAME_PLACING_DYNAMIC_DEPTH
|
||||
#ifdef DEAL_WITH_HORIZON_EFFECT
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
depth_t depthTable[] = { 4, 11, 12, 13, 14, 14, 14, 12, 11, 10, 6, 6, 1 };
|
||||
#else // HASH_MAP_ENABLE
|
||||
#else // TRANSPOSITION_TABLE_ENABLE
|
||||
depth_t depthTable[] = { 2, 11, 11, 11, 11, 10, 9, 8, 8, 8, 7, 7, 1 };
|
||||
#endif // HASH_MAP_ENABLE
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
#else // DEAL_WITH_HORIZON_EFFECT
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef RAPID_GAME
|
||||
depth_t depthTable[] = { 6, 14, 15, 16, 15, 15, 15, 13, 10, 9, 8, 7, 1 };
|
||||
#else
|
||||
depth_t depthTable[] = { 6, 15, 16, 17, 16, 16, 16, 14, 13, 12, 9, 7, 1 };
|
||||
//depth_t depthTable[] = { 6, 15, 16, 17, 16, 16, 16, 12, 12, 12, 9, 7, 1 };
|
||||
#endif // RAPID_GAME
|
||||
#else // HASH_MAP_ENABLE
|
||||
#else // TRANSPOSITION_TABLE_ENABLE
|
||||
depth_t depthTable[] = { 2, 13, 13, 13, 12, 11, 10, 9, 9, 8, 8, 7, 1 };
|
||||
#endif
|
||||
#endif // DEAL_WITH_HORIZON_EFFECT
|
||||
|
@ -133,13 +133,13 @@ struct MillGameAi_ab::Node *MillGameAi_ab::addNode(
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG_AB_TREE
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
newNode->hash = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_AB_TREE
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
newNode->isHash = false;
|
||||
#endif
|
||||
#endif
|
||||
|
@ -271,9 +271,9 @@ void MillGameAi_ab::setGame(const MillGame &game)
|
|||
{
|
||||
// 如果规则改变,重建hashmap
|
||||
if (strcmp(this->game_.currentRule.name, game.currentRule.name) != 0) {
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
clearHashMap();
|
||||
#endif // HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
clearTranspositionTable();
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
#ifdef BOOK_LEARNING
|
||||
// TODO: 规则改变时清空学习表
|
||||
|
@ -362,9 +362,9 @@ int MillGameAi_ab::alphaBetaPruning(depth_t depth)
|
|||
#ifdef IDS_SUPPORT
|
||||
// 深化迭代
|
||||
for (depth_t i = 2; i < d; i += 1) {
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef CLEAR_HASH_MAP
|
||||
clearHashMap(); // 每次走子前清空哈希表
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef CLEAR_TRANSPOSITION_TABLE
|
||||
clearTranspositionTable(); // 每次走子前清空哈希表
|
||||
#endif
|
||||
#endif
|
||||
alphaBetaPruning(i, -INF_VALUE, INF_VALUE, rootNode);
|
||||
|
@ -374,9 +374,9 @@ int MillGameAi_ab::alphaBetaPruning(depth_t depth)
|
|||
loggerDebug("IDS Time: %llus\n", chrono::duration_cast<chrono::seconds>(timeEnd - timeStart).count());
|
||||
#endif /* IDS_SUPPORT */
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef CLEAR_HASH_MAP
|
||||
clearHashMap(); // 每次走子前清空哈希表
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef CLEAR_TRANSPOSITION_TABLE
|
||||
clearTranspositionTable(); // 每次走子前清空哈希表
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -404,7 +404,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
// 子节点的最优着法
|
||||
move_t bestMove = 0;
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING))
|
||||
// 哈希值
|
||||
HashValue hashValue {};
|
||||
memset(&hashValue, 0, sizeof(hashValue));
|
||||
|
@ -419,16 +419,13 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
// 检索 hashmap
|
||||
//hashMapMutex.lock();
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
HashType type = hashfEMPTY;
|
||||
|
||||
value_t probeVal = probeHash(hash, depth, alpha, beta, bestMove, type);
|
||||
|
||||
if (probeVal != INT16_MIN /* TODO: valUNKOWN */ && node != rootNode) {
|
||||
#ifdef HASH_MAP_DEBUG
|
||||
#ifdef TRANSPOSITION_TABLE_DEBUG
|
||||
hashHitCount++;
|
||||
#endif
|
||||
#ifdef DEBUG_AB_TREE
|
||||
|
@ -454,7 +451,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
}
|
||||
|
||||
//hashMapMutex.unlock();
|
||||
#endif /* HASH_MAP_ENABLE */
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||
|
||||
#ifdef DEBUG_AB_TREE
|
||||
node->depth = depth;
|
||||
|
@ -464,10 +461,10 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
node->isLeaf = false;
|
||||
node->isTimeout = false;
|
||||
node->visited = true;
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
node->isHash = false;
|
||||
node->hash = 0;
|
||||
#endif // HASH_MAP_ENABLE
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
#endif // DEBUG_AB_TREE
|
||||
|
||||
// 搜索到叶子节点(决胜局面) // TODO: 对哈希进行特殊处理
|
||||
|
@ -487,7 +484,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
node->isLeaf = true;
|
||||
#endif
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
// 记录确切的哈希值
|
||||
recordHash(node->value, depth, hashfEXACT, hash, 0);
|
||||
#endif
|
||||
|
@ -524,7 +521,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
// 记录确切的哈希值
|
||||
recordHash(node->value, depth, hashfEXACT, hash, 0);
|
||||
#endif
|
||||
|
@ -578,7 +575,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
// 如果某个着法的结果小于或等于 α,那么它就是很差的着法,因此可以抛弃
|
||||
|
||||
if (value > alpha) {
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
hashf = hashfEXACT;
|
||||
#endif
|
||||
alpha = value;
|
||||
|
@ -606,7 +603,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
|
||||
#if 0
|
||||
if (value < beta) {
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
hashf = hashfBETA;
|
||||
#endif
|
||||
beta = value;
|
||||
|
@ -647,10 +644,10 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
|
|||
sortLegalMoves(node);
|
||||
#endif // IDS_SUPPORT
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
// 记录不一定确切的哈希值
|
||||
recordHash(node->value, depth, hashf, hash, node->children[0]->move);
|
||||
#endif /* HASH_MAP_ENABLE */
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||
|
||||
// 返回
|
||||
return node->value;
|
||||
|
@ -741,8 +738,8 @@ const char* MillGameAi_ab::bestMove()
|
|||
nodeCount = 0;
|
||||
evaluatedNodeCount = 0;
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef HASH_MAP_DEBUG
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_DEBUG
|
||||
loggerDebug(""Hash hit count: %llu\n", hashHitCount);
|
||||
#endif
|
||||
#endif
|
||||
|
@ -774,15 +771,15 @@ const char *MillGameAi_ab::move2string(move_t move)
|
|||
return cmdline;
|
||||
}
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
value_t MillGameAi_ab::probeHash(hash_t hash,
|
||||
depth_t depth, value_t alpha, value_t beta,
|
||||
move_t &bestMove, HashType &type)
|
||||
depth_t depth, value_t alpha, value_t beta,
|
||||
move_t &bestMove, HashType &type)
|
||||
{
|
||||
const value_t valUNKNOWN = INT16_MIN;
|
||||
HashValue hashValue {};
|
||||
|
||||
if (!hashmap.find(hash, hashValue)) {
|
||||
if (!transpositionTable.find(hash, hashValue)) {
|
||||
return valUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -813,7 +810,7 @@ out:
|
|||
|
||||
bool MillGameAi_ab::findHash(hash_t hash, HashValue &hashValue)
|
||||
{
|
||||
return hashmap.find(hash, hashValue);
|
||||
return transpositionTable.find(hash, hashValue);
|
||||
|
||||
// TODO: 变换局面
|
||||
#if 0
|
||||
|
@ -860,20 +857,20 @@ int MillGameAi_ab::recordHash(value_t value, depth_t depth, HashType type, hash_
|
|||
hashValue.type = type;
|
||||
hashValue.bestMove = bestMove;
|
||||
|
||||
hashmap.insert(hash, hashValue);
|
||||
transpositionTable.insert(hash, hashValue);
|
||||
|
||||
//hashMapMutex.unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MillGameAi_ab::clearHashMap()
|
||||
void MillGameAi_ab::clearTranspositionTable()
|
||||
{
|
||||
//hashMapMutex.lock();
|
||||
hashmap.clear();
|
||||
transpositionTable.clear();
|
||||
//hashMapMutex.unlock();
|
||||
}
|
||||
#endif /* HASH_MAP_ENABLE */
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||
|
||||
#ifdef BOOK_LEARNING
|
||||
|
||||
|
|
|
@ -82,16 +82,16 @@ public:
|
|||
int nPiecesNeedRemove; // 手中有多少可去的子,如对手有可去的子则为负数
|
||||
int result; // 终局结果,-1为负,0为未到终局,1为胜,走棋阶段被闷棋则为 -2/2,布局阶段闷棋为 -3
|
||||
struct Node* root; // 根节点
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
bool isHash; // 是否从 Hash 读取
|
||||
#endif /* HASH_MAP_ENABLE */
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
hash_t hash; // 哈希值
|
||||
#endif
|
||||
#endif /* DEBUG_AB_TREE */
|
||||
};
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING))
|
||||
// 定义哈希值的类型
|
||||
enum HashType : uint8_t
|
||||
{
|
||||
|
@ -133,9 +133,9 @@ public:
|
|||
// 返回最佳走法的命令行
|
||||
const char *bestMove();
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING))
|
||||
// 清空哈希表
|
||||
void clearHashMap();
|
||||
void clearTranspositionTable();
|
||||
#endif
|
||||
|
||||
// 比较函数
|
||||
|
@ -205,14 +205,14 @@ protected:
|
|||
// 篡改深度
|
||||
depth_t changeDepth(depth_t originalDepth);
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
// 查找哈希表
|
||||
bool findHash(hash_t hash, HashValue &hashValue);
|
||||
value_t probeHash(hash_t hash, depth_t depth, value_t alpha, value_t beta, move_t &bestMove, HashType &type);
|
||||
|
||||
// 插入哈希表
|
||||
int recordHash(value_t value, depth_t depth, HashType type, hash_t hash, move_t bestMove);
|
||||
#endif // HASH_MAP_ENABLE
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
private:
|
||||
// 原始模型
|
||||
|
@ -235,8 +235,8 @@ private:
|
|||
// 评估过的结点个数
|
||||
size_t evaluatedNodeCount {0};
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef HASH_MAP_DEBUG
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_DEBUG
|
||||
// Hash 统计数据
|
||||
size_t hashEntryCount;
|
||||
size_t hashHitCount;
|
||||
|
@ -262,9 +262,9 @@ private:
|
|||
char cmdline[64] {};
|
||||
};
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
extern HashMap<hash_t, MillGameAi_ab::HashValue> hashmap;
|
||||
#endif /* #ifdef HASH_MAP_ENABLE */
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
extern HashMap<hash_t, MillGameAi_ab::HashValue> transpositionTable;
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||
|
||||
#ifdef THREEFOLD_REPETITION
|
||||
extern vector<hash_t> positions;
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#include "tt.h"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef TT_H
|
||||
#define TT_H
|
||||
|
||||
#endif /* TT_H */
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "millgame.h"
|
||||
|
||||
static const hash_t zobrist0[Board::N_POINTS][POINT_TYPE_COUNT] = {
|
||||
#ifdef HASH_MAP_CUTDOWN
|
||||
#ifdef TRANSPOSITION_TABLE_CUTDOWN
|
||||
{0x4E421A00, 0x3962FF00, 0x6DB6EE00, 0x219AE100},
|
||||
{0x1F3DE200, 0xD9AACB00, 0xD5173300, 0xD3F9EA00},
|
||||
{0xF5A7BB00, 0xDC410900, 0xEE431900, 0x7CDA7A00},
|
||||
|
@ -105,7 +105,7 @@ static const hash_t zobrist0[Board::N_POINTS][POINT_TYPE_COUNT] = {
|
|||
{0xFD34EA18D01A6E00, 0xFA1300F7BCD93500, 0xAAC5CC6817565900, 0xE0C64BA5AD5A7300},
|
||||
{0x5ECF7987B04E7D00, 0xAB38FFE6815F5300, 0x94EA1A1812469A00, 0x20EDFF94B2F25C00},
|
||||
{0x0B2D4606564E4B00, 0x83381E3CD1943700, 0xD3DB04A0A4F63C00, 0x789C60EF7169E500}
|
||||
#endif /* HASH_MAP_CUTDOWN */
|
||||
#endif /* TRANSPOSITION_TABLE_CUTDOWN */
|
||||
};
|
||||
|
||||
#ifdef ONLY_USED_FOR_CONVERT
|
||||
|
|
|
@ -66,10 +66,10 @@ void AiThread::setAi(const MillGame &game)
|
|||
this->game_ = &game;
|
||||
ai_ab.setGame(*(this->game_));
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
// 新下一盘前清除哈希表 (注意可能同时存在每步之前清除)
|
||||
#ifdef CLEAR_HASH_MAP
|
||||
ai_ab.clearHashMap();
|
||||
#ifdef CLEAR_TRANSPOSITION_TABLE
|
||||
ai_ab.clearTranspositionTable();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ MillGame::MillGame()
|
|||
// 单独提出 board 等数据,免得每次都写 context.board;
|
||||
board_ = context.board.board_;
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
// 创建哈希数据
|
||||
constructHash();
|
||||
#endif
|
||||
|
@ -173,7 +173,7 @@ bool MillGame::setContext(const struct Rule *rule, step_t maxStepsLedToDraw, int
|
|||
// 当前棋局(3×8)
|
||||
if (board == nullptr) {
|
||||
memset(context.board.board_, 0, sizeof(context.board.board_));
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
context.hash = 0;
|
||||
#endif
|
||||
} else {
|
||||
|
@ -328,7 +328,7 @@ bool MillGame::reset()
|
|||
// 用时置零
|
||||
elapsedSeconds_1 = elapsedSeconds_2 = 0;
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
// 哈希归零
|
||||
context.hash = 0;
|
||||
#endif
|
||||
|
@ -426,7 +426,7 @@ bool MillGame::place(int pos, int time_p, int8_t rs)
|
|||
|
||||
board_[pos] = piece;
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
updateHash(pos);
|
||||
#endif
|
||||
move_ = pos;
|
||||
|
@ -524,13 +524,13 @@ bool MillGame::place(int pos, int time_p, int8_t rs)
|
|||
|
||||
board_[pos] = board_[currentPos];
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
updateHash(pos);
|
||||
#endif
|
||||
|
||||
board_[currentPos] = '\x00';
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
revertHash(currentPos);
|
||||
#endif
|
||||
|
||||
|
@ -620,15 +620,15 @@ bool MillGame::capture(int pos, int time_p, int8_t cp)
|
|||
|
||||
// 去子(设置禁点)
|
||||
if (currentRule.hasForbiddenPoint && context.stage == GAME_PLACING) {
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
revertHash(pos);
|
||||
#endif
|
||||
board_[pos] = '\x0f';
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
updateHash(pos);
|
||||
#endif
|
||||
} else { // 去子
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
revertHash(pos);
|
||||
#endif
|
||||
board_[pos] = '\x00';
|
||||
|
@ -651,7 +651,7 @@ bool MillGame::capture(int pos, int time_p, int8_t cp)
|
|||
|
||||
currentPos = 0;
|
||||
context.nPiecesNeedRemove--;
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
updateHash(pos);
|
||||
#endif
|
||||
|
||||
|
@ -1093,7 +1093,7 @@ void MillGame::cleanForbiddenPoints()
|
|||
pos = r * Board::N_SEATS + s;
|
||||
|
||||
if (board_[pos] == '\x0f') {
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
revertHash(pos);
|
||||
#endif
|
||||
board_[pos] = '\x00';
|
||||
|
@ -1184,7 +1184,7 @@ void MillGame::getElapsedTime(time_t &p1_ms, time_t &p2_ms)
|
|||
p2_ms = elapsedSeconds_2;
|
||||
}
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
|
||||
#if 0
|
||||
/*
|
||||
|
@ -1275,4 +1275,4 @@ hash_t MillGame::updateHashMisc()
|
|||
|
||||
return context.hash;
|
||||
}
|
||||
#endif /* HASH_MAP_ENABLE etc. */
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE etc. */
|
||||
|
|
|
@ -41,13 +41,13 @@ class GameContext
|
|||
public:
|
||||
Board board;
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
// 局面的哈希值
|
||||
hash_t hash{};
|
||||
|
||||
// Zobrist 数组
|
||||
hash_t zobrist[Board::N_POINTS][POINT_TYPE_COUNT]{};
|
||||
#endif /* HASH_MAP_ENABLE */
|
||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||
|
||||
// 局面阶段标识
|
||||
enum GameStage stage;
|
||||
|
@ -322,7 +322,7 @@ public:
|
|||
bool place(int pos, int time_p = -1, int8_t cp = 0);
|
||||
bool capture(int pos, int time_p = -1, int8_t cp = 0);
|
||||
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
#if ((defined TRANSPOSITION_TABLE_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
// hash相关
|
||||
hash_t getHash();
|
||||
hash_t revertHash(int pos);
|
||||
|
|
|
@ -29,11 +29,11 @@ using step_t = uint16_t;
|
|||
using value_t = int16_t;
|
||||
using depth_t = uint8_t;
|
||||
|
||||
#ifdef HASH_MAP_CUTDOWN
|
||||
#ifdef TRANSPOSITION_TABLE_CUTDOWN
|
||||
using hash_t = uint32_t;
|
||||
#else
|
||||
using hash_t = uint64_t;
|
||||
#endif /* HASH_MAP_CUTDOWN */
|
||||
#endif /* TRANSPOSITION_TABLE_CUTDOWN */
|
||||
|
||||
// 移动方向,包括顺时针、逆时针、向内、向外4个方向
|
||||
enum MoveDirection
|
||||
|
|
Loading…
Reference in New Issue