Skip to content

Commit

Permalink
Fail-Soft AB pruning (+18 tokens)
Browse files Browse the repository at this point in the history
Also disallows LMP and FP on first move

10+0.01s
Score of Dev vs Main: 291 - 222 - 429  [0.537] 942
...      Dev playing White: 154 - 113 - 204  [0.544] 471
...      Dev playing Black: 137 - 109 - 225  [0.530] 471
...      White vs Black: 263 - 250 - 429  [0.507] 942
Elo difference: 25.5 +/- 16.4, LOS: 99.9 %, DrawRatio: 45.5 %
SPRT: llr 2.95 (100.1%), lbound -2.94, ubound 2.94 - H1 was accepted
  • Loading branch information
codedeliveryservice committed Sep 17, 2023
1 parent ab08e99 commit 2e79f27
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Chess-Challenge/src/My Bot/MyBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ private int AlphaBeta(int depth, int alpha, int beta, bool nullMoveAllowed = tru
bool inQSearch = depth <= 0;

int staticScore = EvaluateStatically(),
bestScore = -20_000_000, // Mate score
moveCount = 0,
nodeFlag = 3,
score;

if (inQSearch)
{
if (staticScore >= beta) return beta;
bestScore = staticScore;
if (staticScore >= beta) return staticScore;
if (alpha < staticScore) alpha = staticScore;
}
else if (!root && (board.IsRepeatedPosition() || board.IsFiftyMoveDraw()))
Expand All @@ -238,7 +240,7 @@ private int AlphaBeta(int depth, int alpha, int beta, bool nullMoveAllowed = tru
{
// Static null move pruning (reverse futility pruning)
if (depth < 8 && beta <= staticScore - RFPMargin * depth)
return beta;
return staticScore;

// Null move pruning: check if we beat beta even without moving
if (nullMoveAllowed && depth >= 2 && staticScore >= beta)
Expand All @@ -261,9 +263,7 @@ private int AlphaBeta(int depth, int alpha, int beta, bool nullMoveAllowed = tru

foreach (Move move in moves)
{
moveCount++;

if (!inQSearch && !root && !pvNode && !inCheck)
if (moveCount++ > 0 && !inQSearch && !root && !pvNode && !inCheck)
{
// Late move pruning: if we've tried enough moves at low depth, skip the rest
if (depth < 4 && moveCount >= LMPMargin * depth)
Expand Down Expand Up @@ -302,6 +302,9 @@ private int AlphaBeta(int depth, int alpha, int beta, bool nullMoveAllowed = tru
if (depth > 3 && HardTimeLimit * timer.MillisecondsElapsedThisTurn > timer.MillisecondsRemaining)
return 0;

if (score > bestScore)
bestScore = score;

if (score > alpha)
{
latestAlpha = moveCount; // #DEBUG
Expand Down Expand Up @@ -336,10 +339,10 @@ private int AlphaBeta(int depth, int alpha, int beta, bool nullMoveAllowed = tru
if (!inQSearch && moveCount < 1)
return inCheck ? board.PlyCount - 20_000_000 : 0;

transpositionTable[zobrist % TABLE_SIZE] = (zobrist, depth, alpha, nodeFlag, ttMove);
transpositionTable[zobrist % TABLE_SIZE] = (zobrist, depth, bestScore, nodeFlag, ttMove);
stats.TracePVOrAllNodes(nodeFlag, latestAlpha); // #DEBUG

return alpha;
return bestScore;

void UpdateHistory(Move move, int bonus)
{
Expand Down

0 comments on commit 2e79f27

Please sign in to comment.