Skip to content

Commit

Permalink
- update_continuation_histories()でのbonus値、調整。
Browse files Browse the repository at this point in the history
- historyまわりの係数調整。
- 変数名 quietMoveBonus ⇨  bonus
- 変数名 quietMoveMalus ⇨  malus
  • Loading branch information
yaneurao committed Nov 27, 2024
1 parent 9504946 commit 0819a68
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
26 changes: 13 additions & 13 deletions source/engine/yaneuraou-engine/yaneuraou-param.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

// Reductionsテーブルの初期化用
// 重要度 ★★★★★
// 元の値 = Stockfish 16 : 2037 , Stockfish 17(2024.8) : 1843 ,Stockfish 17(2024.11) : 1943 , step = 8
// 元の値 = Stockfish 16 : 2037 , Stockfish 17 : 1843,1943 , step = 8
// [PARAM] min:1500,max:2500,step:2,interval:2,time_rate:1,fixed
PARAM_DEFINE PARAM_REDUCTIONS_PARAM1 = 1943;

Expand Down Expand Up @@ -73,22 +73,22 @@ PARAM_DEFINE PARAM_FUTILITY_MARGIN_ALPHA2 = 27;
PARAM_DEFINE PARAM_FUTILITY_MARGIN_BETA = 108;

// 重要度 ★★★☆☆
// 元の値 = Stockfish 14 : 197 , Stockfish 16 : 239 , Stockfish 17 : 300 , step = 20
// 元の値 = Stockfish 14 : 197 , Stockfish 16 : 239 , Stockfish 17 : 300 , 287 , step = 20
// [PARAM] min:100,max:400,step:30,interval:2,time_rate:1,fixed
PARAM_DEFINE PARAM_FUTILITY_EVAL1 = 300;
PARAM_DEFINE PARAM_FUTILITY_EVAL1 = 287;

// 重要度 ★★★☆☆
// 元の値 = Stockfish 14 : 248 , Stockfish 16 : 291 , Stockfish 17 : 238 , step = 20
// 元の値 = Stockfish 14 : 248 , Stockfish 16 : 291 , Stockfish 17 : 238 , 253, step = 20
// [PARAM] min:100,max:240,step:30,interval:2,time_rate:1,fixed
PARAM_DEFINE PARAM_FUTILITY_EVAL2 = 238;
PARAM_DEFINE PARAM_FUTILITY_EVAL2 = 253;



// 静止探索でのfutility pruning
// 重要度 ★★★★☆
// 元の値 = Stockfish 14 : 200 , Stockfish 16 : 200 , Stockfish 17 : 280 , step = 20
// 元の値 = Stockfish 14 : 200 , Stockfish 16 : 200 , Stockfish 17 : 280 , 306 , step = 20
// [PARAM] min:50,max:300,step:30,interval:1,time_rate:1,
PARAM_DEFINE PARAM_FUTILITY_MARGIN_QUIET = 280;
PARAM_DEFINE PARAM_FUTILITY_MARGIN_QUIET = 306;

// futility pruningの適用depth。
// 重要度 ★★★☆☆
Expand All @@ -110,17 +110,17 @@ PARAM_DEFINE PARAM_FUTILITY_AT_PARENT_NODE_DEPTH = 12;
// 重要度 ★★★★★
// このパラメーター、lmrDepth * lmrDepthに比例するので、影響がすごく大きい。
// 調整には気をつけること。
// 元の値 = Stockfish 14 : 31 , Stockfish 16 : 26 , Stockfish 17 : 24, step = 2
// 元の値 = Stockfish 14 : 31 , Stockfish 16 : 26 , Stockfish 17 : 24,25, step = 2
// [PARAM] min:15,max:50,step:2,interval:1,time_rate:1,fixed
PARAM_DEFINE PARAM_FUTILITY_AT_PARENT_NODE_GAMMA1 = 24;
PARAM_DEFINE PARAM_FUTILITY_AT_PARENT_NODE_GAMMA1 = 25;


// lmrのときのseeの値。
// 重要度 ★★★★☆
// Stockfishの7,8割ぐらいの値にするのがよさげ。
// 元の値 = Stockfish 17 : 167 ,step = 40
// 元の値 = Stockfish 17 : 167 , 162, step = 40
// [PARAM] min:0,max:300,step:10,interval:1,time_rate:1
PARAM_DEFINE PARAM_LMR_SEE_MARGIN1 = 167;
PARAM_DEFINE PARAM_LMR_SEE_MARGIN1 = 162;



Expand Down Expand Up @@ -229,10 +229,10 @@ PARAM_DEFINE PARAM_LMR_MARGIN2 = 13;

// 重要度 ★★☆☆☆
// → 重要なパラメーターではあるが、下手にいじらないほうがよさげ。
// 元の値 = Stockfish 14 : 95 , Stockfish 16 : 90 , Stockfish 17 : 82 , step = 10
// 元の値 = Stockfish 14 : 95 , Stockfish 16 : 90 , Stockfish 17 : 82 ,83 , step = 10
// min:0,max:128,step:1,interval:1,time_rate:1,
// [PARAM] min:50,max:200,step:10,interval:1,time_rate:1,fixed
PARAM_DEFINE PARAM_BAD_ENOUGH_SEE_VALUE = 82;
PARAM_DEFINE PARAM_BAD_ENOUGH_SEE_VALUE = 83;


//
Expand Down
40 changes: 20 additions & 20 deletions source/engine/yaneuraou-engine/yaneuraou-search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2619,8 +2619,8 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo
{
// TODO : ここのパラメーター、調整すべきか? 2 Eloだから無視していいか…。
int futilityValue = ss->staticEval
+ PARAM_FUTILITY_EVAL1/*300*/
+ PARAM_FUTILITY_EVAL2/*238*/ * lmrDepth
+ PARAM_FUTILITY_EVAL1
+ PARAM_FUTILITY_EVAL2 * lmrDepth
+ captHist / 7;

if (futilityValue <= alpha)
Expand All @@ -2630,9 +2630,9 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo
// SEE based pruning for captures and checks (~11 Elo)
// 駒取りや王手に対するSEE(静的交換評価)に基づく枝刈り(約11 Elo)

int seeHist = std::clamp(captHist / 32, -159 * depth, 160 * depth);
int seeHist = std::clamp(captHist / 33, -161 * depth, 156 * depth);

if (!pos.see_ge(move, - Value(PARAM_LMR_SEE_MARGIN1/*167*/) * depth))
if (!pos.see_ge(move, - Value(PARAM_LMR_SEE_MARGIN1) * depth))
continue;
}
else
Expand All @@ -2647,19 +2647,19 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo
// Continuation history based pruning (~2 Elo)
// Continuation historyに基づいた枝刈り(historyの値が悪いものに関してはskip)

if (history < -4071 * depth)
if (history < -3884 * depth)
continue;

history += 2 * thisThread->mainHistory(us, move.from_to());

lmrDepth += history / 3653;
lmrDepth += history / 3609;

// 親nodeの時点で子nodeを展開する前にfutilityの対象となりそうなら枝刈りしてしまう。
// → パラメーター調整の係数を調整したほうが良いのかも知れないが、
//  ここ、そんなに大きなEloを持っていないので、調整しても…。

Value futilityValue =
ss->staticEval + (bestValue < ss->staticEval - 51 ? 145 : 49) + 144 * lmrDepth;
ss->staticEval + (bestValue < ss->staticEval - 45 ? 140 : 43) + 141 * lmrDepth;

// Futility pruning: parent node (~13 Elo)
if (!ss->inCheck && lmrDepth < PARAM_FUTILITY_AT_PARENT_NODE_DEPTH/*12*/ && futilityValue <= alpha)
Expand All @@ -2685,7 +2685,7 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo
// 負のSEEを持つ指し手を枝刈りする(約4 Elo)
// ⇨ lmrDepthの2乗に比例するのでこのパラメーターの影響はすごく大きい。

if (!pos.see_ge(move, Value(- PARAM_FUTILITY_AT_PARENT_NODE_GAMMA1/*24*/ * lmrDepth * lmrDepth)))
if (!pos.see_ge(move, Value(- PARAM_FUTILITY_AT_PARENT_NODE_GAMMA1 * lmrDepth * lmrDepth)))
continue;
}
}
Expand Down Expand Up @@ -3834,7 +3834,7 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth)
{
// bestValueを少しbetaのほうに寄せる。
if (std::abs(bestValue) < VALUE_TB_WIN_IN_MAX_PLY)
bestValue = (3 * bestValue + beta) / 4;
bestValue = (bestValue + beta) / 2;

if (!ss->ttHit)
ttWriter.write(posKey, value_to_tt(bestValue, ss->ply), false, BOUND_LOWER,
Expand All @@ -3851,7 +3851,7 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth)

// futilityの基準となる値をbestValueにmargin値を加算したものとして、
// これを下回るようであれば枝刈りする。
futilityBase = ss->staticEval + PARAM_FUTILITY_MARGIN_QUIET/*280*/;
futilityBase = ss->staticEval + PARAM_FUTILITY_MARGIN_QUIET;

}

Expand Down Expand Up @@ -3988,13 +3988,13 @@ Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth)
// 成りでない && seeが負の指し手はNG。王手回避でなくとも、同様。

if (!capture
&& (*contHist[0])(pos.moved_piece_after(move), move.to_sq())
&& (*contHist[0])(pos.moved_piece_after(move), move.to_sq())
+ (*contHist[1])(pos.moved_piece_after(move), move.to_sq())
/*
+ thisThread->pawnHistory[pawn_structure_index(pos)][pos.moved_piece(move)]
[move.to_sq()]
*/
<= 5036 /* TODO : ここ、調整すべき */)
<= 5095 /* TODO : ここ、調整すべき */)
continue;

// Do not search moves with bad enough SEE values (~5 Elo)
Expand Down Expand Up @@ -4265,27 +4265,27 @@ void update_all_stats(
Piece moved_piece = pos.moved_piece_after(bestMove);
PieceType captured;

int quietMoveBonus = stat_bonus(depth + 1);
int quietMoveMalus = stat_malus(depth );
int bonus = stat_bonus(depth + 1);
int malus = stat_malus(depth );

// Stockfish 14ではcapture_or_promotion()からcapture()に変更された。[2022/3/23]
// Stockfish 16では、capture()からcapture_stage()に変更された。[2023/10/15]
if (!pos.capture_stage(bestMove))
{
update_quiet_histories(pos, ss, bestMove, quietMoveBonus);
update_quiet_histories(pos, ss, bestMove, bonus);

// Decrease stats for all non-best quiet moves
// 最善でないquietの指し手すべての統計を減少させる

for (Move move : quietsSearched)
update_quiet_histories(pos, ss, /*workerThread,*/ move, -quietMoveMalus);
update_quiet_histories(pos, ss, /*workerThread,*/ move, -malus);
}
else {
// Increase stats for the best move in case it was a capture move
// 最善手が捕獲する指し手だった場合、その統計を増加させる

captured = type_of(pos.piece_on(bestMove.to_sq()));
captureHistory(moved_piece, bestMove.to_sq(), captured) << quietMoveBonus;
captureHistory(moved_piece, bestMove.to_sq(), captured) << bonus;
}

// Extra penalty for a quiet early move that was not a TT move in
Expand All @@ -4301,7 +4301,7 @@ void update_all_stats(
&& ( (ss - 1)->moveCount == 1 + (ss - 1)->ttHit )
&& !pos.captured_piece()
)
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq, -quietMoveMalus);
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq, -malus);

// Decrease stats for all non-best capture moves
// 最善の捕獲する指し手以外のすべての手の統計を減少させます
Expand All @@ -4313,7 +4313,7 @@ void update_all_stats(
// それに倣う必要がある。
moved_piece = pos.moved_piece_after(move);
captured = type_of(pos.piece_on(move.to_sq()));
captureHistory(moved_piece, move.to_sq(), captured) << -quietMoveMalus;
captureHistory(moved_piece, move.to_sq(), captured) << -malus;
}
}

Expand All @@ -4330,7 +4330,7 @@ void update_all_stats(
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus)
{
// これstat_bonusの計算のときに係数を掛けておくべきでは…。
bonus = bonus * 53 / 64;
bonus = bonus * 50 / 64;

for (int i : {1, 2, 3, 4, 6})
//for (int i : {1, 2, 4, 6})
Expand Down

0 comments on commit 0819a68

Please sign in to comment.