From 1ca61b7f4c3ac07b39b6a3064a1a54d14e4b41b0 Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Sun, 21 Jul 2019 19:51:26 +0800 Subject: [PATCH] =?UTF-8?q?BOOK:=20=E5=8F=B6=E5=AD=90=E7=BB=93=E7=82=B9?= =?UTF-8?q?=E6=89=8D=E8=AE=B0=E5=BD=95=E5=BC=80=E5=B1=80=E5=BA=93=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E5=87=A0=E4=B9=8E=E6=89=80=E6=9C=89=E5=B1=80=E9=9D=A2?= =?UTF-8?q?=E9=83=BD=E8=AE=B0=E5=BD=95=E5=88=B0=E5=BC=80=E5=B1=80=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NineChess/src/ninechessai_ab.cpp | 36 ++++++++++++-------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/NineChess/src/ninechessai_ab.cpp b/NineChess/src/ninechessai_ab.cpp index 47d5057c..b329e242 100644 --- a/NineChess/src/ninechessai_ab.cpp +++ b/NineChess/src/ninechessai_ab.cpp @@ -573,8 +573,8 @@ int NineChessAi_ab::alphaBetaPruning(int depth) #ifdef BOOK_LEARNING if (chess_.getStage() == NineChess::GAME_PLACING) { - if (chess_.context.nPiecesInHand_1 == 0) { - // 只记录摆棋阶段最后一着的局面 + if (chess_.context.nPiecesInHand_1 <= 10) { + // 开局库只记录摆棋阶段最后的局面 openingBook.push_back(chess_.getHash()); } else { // 暂时在此处清空开局库 @@ -628,11 +628,6 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) // 子节点的最优着法 int bestMove = 0; -#ifdef BOOK_LEARNING - // 是否在开局库中出现过 - bool hitBook = false; -#endif - #if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING)) // 哈希值 HashValue hashValue; @@ -646,16 +641,6 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) node->hash = hash; #endif -#ifdef BOOK_LEARNING - // 检索开局库 - if (chessContext->stage == NineChess::GAME_PLACING && findBookHash(hash, hashValue)) { - if (chessContext->turn == NineChess::PLAYER2) { - // 是否需对后手扣分 // TODO: 先后手都处理 - hitBook = true; - } - } -#endif /* BOOK_LEARNING */ - #ifdef HASH_MAP_ENABLE // 检索 hashmap //hashMapMutex.lock(); @@ -741,6 +726,17 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) } #endif +#ifdef BOOK_LEARNING + // 检索开局库 + if (chessContext->stage == NineChess::GAME_PLACING && findBookHash(hash, hashValue)) { + if (chessContext->turn == NineChess::PLAYER2) { + // 是否需对后手扣分 // TODO: 先后手都处理 + node->value += 1; + // qDebug() << ">>>>>>>>>>>>>>> New soccer = " << node->value; + } + } +#endif + #ifdef HASH_MAP_ENABLE // 记录确切的哈希值 recordHash(node->value, depth, hashfEXACT, hash, 0); @@ -862,12 +858,6 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) recordHash(node->value, depth, hashf, hash, node->children[0]->move); #endif /* HASH_MAP_ENABLE */ -#ifdef BOOK_LEARNING - if (hitBook) { - node->value++; - } -#endif - // 返回 return node->value; }