From 4946785af8563bac7b71c69fb3c62e66a668625f Mon Sep 17 00:00:00 2001 From: PikaCat <760758491@qq.com> Date: Wed, 27 Apr 2022 16:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E8=B5=B0=E6=B3=95=E9=87=87?= =?UTF-8?q?=E7=94=A8=E6=9B=B4=E5=8A=A0=E6=BF=80=E8=BF=9B=E7=9A=84=E8=A3=81?= =?UTF-8?q?=E5=89=AA=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChineseChess.pro.user | 2 +- src/search/searchinstance.cpp | 39 ++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ChineseChess.pro.user b/ChineseChess.pro.user index 517823a..3592930 100644 --- a/ChineseChess.pro.user +++ b/ChineseChess.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/search/searchinstance.cpp b/src/search/searchinstance.cpp index 4793880..7ce327c 100644 --- a/src/search/searchinstance.cpp +++ b/src/search/searchinstance.cpp @@ -13,7 +13,7 @@ void SearchInstance::searchRoot(const qint8 depth) { this->m_killerTable.getKiller(this->m_distance, 1)}; qint16 bestScore { LOSS_SCORE }; - // LMR的计数器 + // LMR/LMP的计数器 quint8 moveSearched { 0 }; this->m_legalMove = 0; // 是否被对方将军 @@ -32,13 +32,20 @@ void SearchInstance::searchRoot(const qint8 depth) { if (moveSearched == 0) { tryScore = -searchFull(LOSS_SCORE, MATE_SCORE, newDepth, NO_NULL); } else { - // LMR,要求当前层数大于等于3,没有被将军,该步不是吃子步,从第4步棋开始往后 - if (moveSearched >= 4 and depth >= 3 and notInCheck and - newDepth not_eq depth and not lastMove.isCapture()) { - tryScore = -searchFull(-bestScore - 1, -bestScore, newDepth - 1); + // 保证搜索正常进行 + tryScore = bestScore + 1; + // LMR/LMP,要求没有被将军,该步不是吃子步 + if (notInCheck and newDepth not_eq depth and not lastMove.isCapture()) { + // LMR,在层数大于等于3时使用 + if (depth >= 3) { + qint8 reduce = 1; + // 靠后的走法采用更加激进的裁剪策略 + if (moveSearched >= 6) reduce = depth / 3; + tryScore = -searchFull(-bestScore - 1, -bestScore, newDepth - reduce); + } + // LMP,在层数小于3时使用,要求已经搜索过了一定数量的走法 + else if (moveSearched > 6 * depth) tryScore = LOSS_SCORE; } - // 其余情况保证搜索正常进行 - else tryScore = bestScore + 1; if (tryScore > bestScore) { tryScore = -searchFull(-bestScore - 1, -bestScore, newDepth); if (tryScore > bestScore) { @@ -166,7 +173,7 @@ qint16 SearchInstance::searchFull(qint16 alpha, const qint16 beta, qint16 bestScore { LOSS_SCORE }; Move bestMove { }; - // LMR的计数器 + // LMR/LMP的计数器 quint8 moveSearched { 0 }; // 遍历所有走法 while ((move = search.getNextMove()).isVaild()) { @@ -179,10 +186,18 @@ qint16 SearchInstance::searchFull(qint16 alpha, const qint16 beta, // PVS if (moveSearched == 0) tryScore = -searchFull(-beta, -alpha, newDepth); else { - // LMR,要求当前层数大于等于3,没有被将军,没有将军别人,该步不是吃子步,从第4步棋开始往后 - if (moveSearched >= 4 and depth >= 3 and notInCheck and - newDepth not_eq depth and not lastMove.isCapture()) { - tryScore = -searchFull(-alpha - 1, -alpha, newDepth - 1); + // 保证搜索正常进行 + tryScore = alpha + 1; + // LMR/LMP,要求没有被将军,该步不是吃子步 + if (notInCheck and newDepth not_eq depth and not lastMove.isCapture()) { + // LMR,在层数大于等于3时使用 + if (depth >= 3) { + qint8 reduce = 1; + if (moveSearched >= 6) reduce = depth / 3; + tryScore = -searchFull(-alpha - 1, -alpha, newDepth - reduce); + } + // LMP,在层数小于3时使用,要求已经搜索过了一定数量的走法 + else if (moveSearched > 6 * depth) tryScore = LOSS_SCORE; } // 其余情况保证搜索正常进行 else tryScore = alpha + 1;