Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
延迟走法采用更加激进的裁剪策略
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaCat committed Apr 27, 2022
1 parent dca90c3 commit 4946785
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ChineseChess.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 7.0.0, 2022-04-27T13:10:34. -->
<!-- Written by QtCreator 7.0.0, 2022-04-27T16:10:25. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
39 changes: 27 additions & 12 deletions src/search/searchinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// 是否被对方将军
Expand All @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down

0 comments on commit 4946785

Please sign in to comment.