From ae247bad5258bb8aceb1607b20a3dc9fbd0308c5 Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Sat, 6 Jul 2019 19:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AA=E5=AF=B9=E6=9C=80=E4=BC=98=E7=9D=80?= =?UTF-8?q?=E6=B3=95=E4=B8=94=E4=B8=BA=E5=90=83=E5=AD=90=E7=9A=84=E7=9D=80?= =?UTF-8?q?=E6=B3=95=E5=A4=9A=E6=90=9C=E7=B4=A2=E4=B8=80=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NineChess/src/config.h | 4 ++-- NineChess/src/ninechessai_ab.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NineChess/src/config.h b/NineChess/src/config.h index 7d470b26..c63d713c 100644 --- a/NineChess/src/config.h +++ b/NineChess/src/config.h @@ -3,7 +3,7 @@ //#define DEBUG -//#define DEAL_WITH_HORIZON_EFFECT +#define DEAL_WITH_HORIZON_EFFECT //#define RANDOM_BEST_MOVE @@ -28,7 +28,7 @@ #define GAME_MOVING_FIXED_DEPTH 3 #else // DEBUG #ifdef DEAL_WITH_HORIZON_EFFECT -#define GAME_MOVING_FIXED_DEPTH 8 +#define GAME_MOVING_FIXED_DEPTH 10 #else // DEAL_WITH_HORIZON_EFFECT #define GAME_MOVING_FIXED_DEPTH 10 #endif // DEAL_WITH_HORIZON_EFFECT diff --git a/NineChess/src/ninechessai_ab.cpp b/NineChess/src/ninechessai_ab.cpp index bc1764b5..b2124f37 100644 --- a/NineChess/src/ninechessai_ab.cpp +++ b/NineChess/src/ninechessai_ab.cpp @@ -444,7 +444,8 @@ int NineChessAi_ab::changeDepth(int originalDepth) if ((chessTemp.context.stage) & (NineChess::GAME_PLACING)) { #ifdef GAME_PLACING_DYNAMIC_DEPTH #ifdef DEAL_WITH_HORIZON_EFFECT - int depthTable[] = { 2, 10, 10, 10, 10, 9, 9, 8, 7, 7, 7, 7, 1 }; + //int depthTable[] = { 2, 11, 11, 11, 11, 10, 9, 8, 8, 8, 7, 7, 1 }; + int depthTable[] = { 2, 12, 12, 12, 12, 11, 10, 9, 9, 9, 8, 7, 1 }; #else //int depthTable[] = { 2, 12, 12, 12, 12, 11, 10, 9, 8, 8, 8, 7, 1 }; int depthTable[] = { 2, 12, 12, 12, 12, 11, 10, 9, 9, 9, 8, 7, 1 }; @@ -592,6 +593,8 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) minMax = chessTemp.whosTurn() == NineChess::PLAYER1 ? -INF_VALUE : INF_VALUE; + int index = 0; + for (auto child : node->children) { // 上下文入栈保存,以便后续撤销着法 contextStack.push(chessTemp.context); @@ -600,14 +603,16 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) chessTemp.command(child->move); #ifdef DEAL_WITH_HORIZON_EFFECT + index++; // 克服“水平线效应”: 若遇到吃子,则搜索深度增加 - if (child->move < 0) { + if (index == 1 && child->move < 0) { epsilon = 1; } else { epsilon = 0; } #endif + // 递归 Alpha-Beta 剪枝 value = alphaBetaPruning(depth - 1 + epsilon, alpha, beta, child);