Skip to content

Commit ea4ad7c

Browse files
committed
Fixed null move check state bug.
1 parent 2e076fa commit ea4ad7c

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

.github/workflows/release-pipeline.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
working-directory: Sapling
2626
id: get_version
2727
run: |
28-
VERSION=1.0.0
28+
VERSION=1.0.1
2929
echo "Application version: $VERSION"
3030
echo "::set-output name=version::$VERSION"
3131

Sapling.Engine/BoardStateExtensions.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public static BoardState CreateBoardFromArray(Piece[] pieces)
139139
boardState.Evaluator.ShouldWhiteMirrored = boardState.WhiteKingSquare.IsMirroredSide();
140140
boardState.Evaluator.ShouldBlackMirrored = boardState.BlackKingSquare.IsMirroredSide();
141141
boardState.Evaluator.FillAccumulators(boardState);
142+
143+
boardState.UpdateCheckStatus();
142144
return boardState;
143145
}
144146

@@ -218,6 +220,7 @@ public static BoardState CreateBoardFromFen(string fen)
218220
boardState.Evaluator.WhiteMirrored = boardState.WhiteKingSquare.IsMirroredSide();
219221
boardState.Evaluator.BlackMirrored = boardState.BlackKingSquare.IsMirroredSide();
220222
boardState.Evaluator.FillAccumulators(boardState);
223+
boardState.UpdateCheckStatus();
221224

222225
return boardState;
223226
}
@@ -588,8 +591,14 @@ public static bool PartialApply(this BoardState board, uint m)
588591
[MethodImpl(MethodImplOptions.AggressiveInlining)]
589592
public static void UpdateCheckStatus(this BoardState board)
590593
{
591-
board.InCheck = (board.WhiteToMove && board.IsAttackedByBlack(board.WhiteKingSquare)) ||
592-
(!board.WhiteToMove && board.IsAttackedByWhite(board.BlackKingSquare));
594+
if (board.WhiteToMove)
595+
{
596+
board.InCheck = board.IsAttackedByBlack(board.WhiteKingSquare);
597+
}
598+
else
599+
{
600+
board.InCheck = board.IsAttackedByWhite(board.BlackKingSquare);
601+
}
593602
}
594603

595604
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -774,11 +783,11 @@ private static void UpdateRepetitions(this BoardState board, uint move)
774783
public static void PartialUnApply(this BoardState board, uint m,
775784
ulong oldHash,
776785
byte oldEnpassant,
777-
bool prevWhiteCheck,
786+
bool prevInCheck,
778787
CastleRights prevCastleRights,
779788
int prevFiftyMoveCounter)
780789
{
781-
board.InCheck = prevWhiteCheck;
790+
board.InCheck = prevInCheck;
782791
board.EnPassantFile = oldEnpassant;
783792
board.TurnCount--;
784793
board.WhiteToMove = !board.WhiteToMove;
@@ -982,15 +991,17 @@ public static void ApplyNullMove(this BoardState board)
982991

983992
board.TurnCount++;
984993
board.WhiteToMove = !board.WhiteToMove;
994+
board.InCheck = false;
985995
}
986996

987997
[MethodImpl(MethodImplOptions.AggressiveInlining)]
988-
public static void UnApplyNullMove(this BoardState board, ulong oldHash, byte oldEnpassant)
998+
public static void UnApplyNullMove(this BoardState board, ulong oldHash, byte oldEnpassant, bool oldCheck)
989999
{
9901000
board.Hash = oldHash;
9911001
board.EnPassantFile = oldEnpassant;
9921002
board.TurnCount--;
9931003
board.WhiteToMove = !board.WhiteToMove;
1004+
board.InCheck = oldCheck;
9941005
}
9951006

9961007
[MethodImpl(MethodImplOptions.AggressiveInlining)]

Sapling.Engine/Search/NegaMaxSearch.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public unsafe int
104104
var nullMoveScore = -NegaMaxSearch(killers, counters, history, depthFromRoot + 1,
105105
Math.Max(depth - reduction - 1, 0), -beta,
106106
-beta + 1, true, prevMove);
107-
Board.UnApplyNullMove(originalHash, oldEnpassant);
107+
Board.UnApplyNullMove(originalHash, oldEnpassant, inCheck);
108108

109109
if (nullMoveScore >= beta)
110110
{

Sapling.Engine/Search/QuiescenceSearch.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public unsafe int QuiescenceSearch(int depthFromRoot, int alpha, int beta)
135135
continue;
136136
}
137137

138+
Board.UpdateCheckStatus();
139+
138140
if (!prevInCheck && !Board.InCheck && scores[moveIndex] < Constants.LosingCaptureBias)
139141
{
140142
//skip playing bad captures when not in check
@@ -145,7 +147,6 @@ public unsafe int QuiescenceSearch(int depthFromRoot, int alpha, int beta)
145147

146148
hasValidMove = true;
147149

148-
Board.UpdateCheckStatus();
149150
Board.FinishApply(m, oldEnpassant, prevCastleRights);
150151

151152
Sse.Prefetch0(_transpositionTable + (Board.Hash & TtMask));

0 commit comments

Comments
 (0)