From 36daf7bb4ffffaa29d7d74f80ed490074c3f6ea6 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 4 May 2020 02:31:28 +0800 Subject: [PATCH] =?UTF-8?q?depth:=20=E7=99=BD=E6=96=B9=E7=AC=AC4=E6=AD=A5?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6=E4=B8=8A=E8=B0=83=E5=88=B018?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顺带将 ai.ttMove 修正为 ai.nextMove() 并且多加了几个 nodeCompare 的 策略但未启用。 自对弈时长 10s 多。对比2000盘自对弈结果,速度为修改前的90%。 自对弈棋谱改变,最后一着为 (2,7)->(2,6) 三次重复局面和棋。 --- include/config.h | 2 ++ src/ai/search.cpp | 41 ++++++++++++++++++++++++++++++++++++----- src/ai/search.h | 2 +- src/base/aithread.cpp | 9 ++------- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/include/config.h b/include/config.h index c5a26e9f..9da51de3 100644 --- a/include/config.h +++ b/include/config.h @@ -107,6 +107,8 @@ #define COMPARE_SCORE_PREFERRED #else #define COMPARE_RATING_ONLY +//#define COMPARE_RATING_1ST_VALUE_2ND +//#define COMPARE_VALUE_1ST_RATING_2ND #endif // HOSTORY_HEURISTIC #define PREFETCH_SUPPORT diff --git a/src/ai/search.cpp b/src/ai/search.cpp index f7c1a65d..e8d5b6ed 100644 --- a/src/ai/search.cpp +++ b/src/ai/search.cpp @@ -83,7 +83,7 @@ depth_t AIAlgorithm::changeDepth(depth_t origDepth) const depth_t placingDepthTable_12[] = { +1, 2, +2, 4, /* 0 ~ 3 */ - +4, 12, +12, 12, /* 4 ~ 7 */ + +4, 12, +12, 18, /* 4 ~ 7 */ +12, 16, +16, 16, /* 8 ~ 11 */ +16, 16, +16, 17, /* 12 ~ 15 */ +17, 16, +16, 15, /* 16 ~ 19 */ @@ -271,7 +271,7 @@ Node *Node::addChild( } #endif // TT_MOVE_ENABLE - // 若没有启用置换表,或启用了但为叶子节点,则 ttMove 为0 + // 若没有启用置换表,或启用了但为叶子节点,则 nextMove 为0 square_t sq = SQ_0; if (m > 0) { @@ -386,6 +386,30 @@ Node *Node::addChild( #ifdef ALPHABETA_AI int AIAlgorithm::nodeCompare(const Node *first, const Node *second) { +#ifdef COMPARE_RATING_1ST_VALUE_2ND + if (first->rating == second->rating) { + if (first->value == second->value) { + return 0; + } + + return (first->value < second->value ? 1 : -1); + } + + return (first->rating < second->rating ? 1 : -1); +#endif + +#ifdef COMPARE_VALUE_1ST_RATING_2ND + if (first->value == second->value) { + if (first->rating == second->rating) { + return 0; + } + + return (first->rating < second->rating ? 1 : -1); + } + + return (first->value < second->value ? 1 : -1); +#endif + #ifdef COMPARE_RATING_ONLY return second->rating - first->rating; #endif @@ -1039,7 +1063,7 @@ void AIAlgorithm::undoNullMove() } #ifdef ALPHABETA_AI -const char* AIAlgorithm::ttMove() +const char* AIAlgorithm::nextMove() { char charChoose = '*'; @@ -1050,11 +1074,15 @@ const char* AIAlgorithm::ttMove() Board::printBoard(); int moveIndex = 0; + bool foundBest = false; int cs = root->childrenSize; for (int i = 0; i < cs; i++) { if (root->children[i]->move != best) { charChoose = ' '; + } else { + charChoose = '*'; + foundBest = true; } loggerDebug("[%.2d] %d\t%s\t%d\t%d\t%u %c\n", moveIndex, @@ -1112,8 +1140,11 @@ const char* AIAlgorithm::ttMove() } #endif // TRANSPOSITION_TABLE_DEBUG #endif // TRANSPOSITION_TABLE_ENABLE - - return moveToCommand(best); + if (foundBest == false) { + assert(0); + } else { + return moveToCommand(best); + } } #endif // ALPHABETA_AI diff --git a/src/ai/search.h b/src/ai/search.h index d90a8be9..6cd35eaa 100644 --- a/src/ai/search.h +++ b/src/ai/search.h @@ -185,7 +185,7 @@ public: int search(depth_t depth); // 返回最佳走法的命令行 - const char *ttMove(); + const char *nextMove(); #endif // ALPHABETA_AI // 暂存局面 diff --git a/src/base/aithread.cpp b/src/base/aithread.cpp index ab068315..17bd7009 100644 --- a/src/base/aithread.cpp +++ b/src/base/aithread.cpp @@ -109,12 +109,7 @@ deque openingBookDeque( 21, 23, 19, 20, 17, 18, - 15, 10, - 26, 12, - 28, 11, - 27, 9, -15, - 29, -12, 25, - 13, -25 + 15, } ); @@ -196,7 +191,7 @@ void AiThread::run() strCommand = "draw"; emitCommand(); } else { - strCommand = ai.ttMove(); + strCommand = ai.nextMove(); if (strCommand && strcmp(strCommand, "error!") != 0) { loggerDebug("Computer: %s\n\n", strCommand); emitCommand();