From 091a208fbe08e3686c2dc2bc9eab4212b600e862 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 21 Oct 2019 00:06:17 +0800 Subject: [PATCH] =?UTF-8?q?AI:=20=E5=85=B3=E9=97=AD=20IDS=20=E5=B9=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4=20rating=20=E8=AE=A1=E7=AE=97=E4=BB=A5?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 关闭IDS, 因为通过判断是否成三来排定走子顺序已经很有效; * 仅在吃子时才统计各个点周围子类型分布; * 仅在需要检测落子点是否能阻止对方成三时才统计点位于对手几个三连中; * 去掉摆子阶段尽量往禁点旁边落子的策略; * 不再判断吃子点处于我方的三连中, 因为可能正好也处于对方的三连中. 自对弈时长 2s, 但走棋阶段没多久就闷杀. 若开 IDS 则是 20s. --- include/config.h | 4 ++-- src/ai/search.cpp | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/config.h b/include/config.h index b5ea7d99..171ab084 100644 --- a/include/config.h +++ b/include/config.h @@ -62,9 +62,9 @@ //#define DEAL_WITH_HORIZON_EFFECT -#define IDS_SUPPORT +//#define IDS_SUPPORT //#define IDS_WINDOW -#define IDS_DEBUG +//#define IDS_DEBUG //#define IDS_ADD_VALUE //#define CLEAR_PRUNED_FLAG_BEFORE_SEARCH diff --git a/src/ai/search.cpp b/src/ai/search.cpp index e5b8d184..1ce3a3fe 100644 --- a/src/ai/search.cpp +++ b/src/ai/search.cpp @@ -244,10 +244,6 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode( // 若没有启用置换表,或启用了但为叶子节点,则 bestMove 为0 if (bestMove == 0 || move != bestMove) { - int nPlayerPiece = 0; - int nOpponentPiece = 0; - int nForbidden = 0; - int nEmpty = 0; square_t sq = SQ_0; if (move > 0) { @@ -258,12 +254,10 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode( sq = (square_t)((-move) & 0x00ff); } - // TODO: 处理移动子的统计 - tempGame.position.board.getSurroundedPieceCount(sq, tempGame.position.sideId, - nPlayerPiece, nOpponentPiece, nForbidden, nEmpty); + int nMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.sideToMove); - int nopponentMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.opponent); + int nopponentMills = 0; #ifdef MILL_FIRST // TODO: rule.allowRemoveMultiPieces 以及 适配打三棋之外的其他规则 @@ -272,20 +266,29 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode( if (nMills > 0) { newNode->rating += static_cast(RATING_ONE_MILL * nMills); } else { - // 检测落子点是否能阻止对方成三 + // 检测落子点是否能阻止对方成三 + nopponentMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.opponent); newNode->rating += static_cast(RATING_BLOCK_ONE_MILL * nopponentMills); } - newNode->rating += static_cast(nForbidden); // 摆子阶段尽量往禁点旁边落子 + //newNode->rating += static_cast(nForbidden); // 摆子阶段尽量往禁点旁边落子 if (tempGame.getPiecesOnBoardCount(2) < 2 && // patch: 仅当白方第2着时 Board::isStar(static_cast(move))) { newNode->rating += RATING_STAR_SQUARE; } - } else if (move < 0) { + } else if (move < 0) { + int nPlayerPiece = 0; + int nOpponentPiece = 0; + int nForbidden = 0; + int nEmpty = 0; + + tempGame.position.board.getSurroundedPieceCount(sq, tempGame.position.sideId, + nPlayerPiece, nOpponentPiece, nForbidden, nEmpty); + if (nMills > 0) { // 吃子点处于我方的三连中 - newNode->rating += static_cast(RATING_CAPTURE_ONE_MILL * nMills); + //newNode->rating += static_cast(RATING_CAPTURE_ONE_MILL * nMills); if (nOpponentPiece == 0) { // 吃子点旁边没有对方棋子则优先考虑 @@ -298,6 +301,7 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode( } // 吃子点处于对方的三连中 + nopponentMills = tempGame.position.board.inHowManyMills(sq, tempGame.position.opponent); if (nopponentMills) { if (nOpponentPiece >= 2) { // 旁边对方的子较多, 则倾向不吃