Add bounds check to repetition table (just in case)

This commit is contained in:
Sebastian Lague 2023-07-30 23:39:14 +02:00
parent 6c9b67aa10
commit 3c5876a8ba

View file

@ -12,7 +12,7 @@ namespace ChessChallenge.Chess
public RepetitionTable()
{
hashes = new ulong[256];
startIndices = new int[hashes.Length];
startIndices = new int[hashes.Length + 1];
}
public void Init(Board board)
@ -31,9 +31,13 @@ namespace ChessChallenge.Chess
public void Push(ulong hash, bool reset)
{
hashes[count] = hash;
// Check bounds just in case
if (count < hashes.Length)
{
hashes[count] = hash;
startIndices[count + 1] = reset ? count : startIndices[count];
}
count++;
startIndices[count] = reset ? count - 1 : startIndices[count - 1];
}
public void TryPop()