diff --git a/NineChess/src/config.h b/NineChess/src/config.h index 162f597c..3d777eb7 100644 --- a/NineChess/src/config.h +++ b/NineChess/src/config.h @@ -3,6 +3,8 @@ //#define DEBUG +#define DEAL_WITH_HORIZON_EFFECT + #ifdef DEBUG #define DONOT_PLAY_SOUND #define DEBUG_AB_TREE @@ -18,11 +20,17 @@ #ifdef DEBUG #define GAME_MOVING_FIXED_DEPTH 3 -#else +#else // DEBUG +#ifdef DEAL_WITH_HORIZON_EFFECT +#define GAME_MOVING_FIXED_DEPTH 4 +#else // DEAL_WITH_HORIZON_EFFECT #define GAME_MOVING_FIXED_DEPTH 10 -#endif +#endif // DEAL_WITH_HORIZON_EFFECT +#endif // DEBUG +#ifndef DEBUG #define GAME_PLACING_DYNAMIC_DEPTH +#endif #ifdef DEBUG #define DRAW_SEAT_NUMBER diff --git a/NineChess/src/ninechessai_ab.cpp b/NineChess/src/ninechessai_ab.cpp index 84b50d15..e67cf3cb 100644 --- a/NineChess/src/ninechessai_ab.cpp +++ b/NineChess/src/ninechessai_ab.cpp @@ -419,11 +419,15 @@ 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1 }; +#else int depthTable[] = { 2, 12, 12, 12, 12, 11, 10, 9, 8, 8, 8, 7, 1 }; +#endif // DEAL_WITH_HORIZON_EFFECT newDepth = depthTable[chessTemp.getPiecesInHandCount_1()]; #elif defined GAME_PLACING_FIXED_DEPTH newDepth = GAME_PLACING_FIXED_DEPTH; -#endif +#endif // GAME_PLACING_DYNAMIC_DEPTH } #ifdef GAME_MOVING_FIXED_DEPTH @@ -473,6 +477,9 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) // 当前节点的MinMax值,最终赋值给节点value,与alpha和Beta不同 int minMax; + // 临时增加的深度 + int epsilon = 0; + #ifdef DEBUG_AB_TREE node->depth = depth; node->root = rootNode; @@ -548,7 +555,18 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node) for (auto child : node->children) { contextStack.push(chessTemp.context); chessTemp.command(child->move); - value = alphaBetaPruning(depth - 1, alpha, beta, child); + +#ifdef DEAL_WITH_HORIZON_EFFECT + // 若遇到吃子,则搜索深度加一层 + if (child->move < 0) { + epsilon = 1; + } + else { + epsilon = 0; + } +#endif + + value = alphaBetaPruning(depth - 1 + epsilon, alpha, beta, child); chessTemp.context = contextStack.top(); contextStack.pop();