book: 完成开局库学习的初版

This commit is contained in:
CalciteM Team 2019-07-17 01:15:14 +08:00
parent d75feb9eea
commit 7fd982c1fc
2 changed files with 17 additions and 6 deletions

View File

@ -3,7 +3,7 @@
//#define DEBUG //#define DEBUG
//#define RANDOM_MOVE #define RANDOM_MOVE
#define DEAL_WITH_HORIZON_EFFECT #define DEAL_WITH_HORIZON_EFFECT

View File

@ -607,7 +607,7 @@ int NineChessAi_ab::alphaBetaPruning(int depth)
openingBook.push_back(chess_.getHash()); openingBook.push_back(chess_.getHash());
} else { } else {
// 暂时在此处清空开局库 // 暂时在此处清空开局库
clearBookHashMap(); openingBook.clear();
} }
} }
#endif #endif
@ -653,6 +653,10 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
// 临时增加的深度,克服水平线效应用 // 临时增加的深度,克服水平线效应用
int epsilon = 0; int epsilon = 0;
#ifdef BOOK_LEARNING
bool hitBook = false; // 是否在开局库中出现过
#endif
#ifdef HASH_MAP_ENABLE #ifdef HASH_MAP_ENABLE
// 哈希值 // 哈希值
HashValue hashValue; HashValue hashValue;
@ -711,10 +715,11 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
// 检索开局库 // 检索开局库
HashValue hashValue; HashValue hashValue;
if (chessContext->turn == NineChess::PLAYER1 && if(findBookHash(hash, hashValue)) {
findBookHash(hash, hashValue)) { if (chessContext->turn == NineChess::PLAYER2) {
// 对走棋一方扣分 // 是否需对后手扣分
node->value--; hitBook = true;
}
} }
#endif #endif
@ -940,6 +945,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
// 排序子节点树 // 排序子节点树
sortLegalMoves(node); // (13%) sortLegalMoves(node); // (13%)
#ifdef BOOK_LEARNING
if (hitBook) {
node->value++;
}
#endif
// 返回 // 返回
return node->value; return node->value;
} }