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() public RepetitionTable()
{ {
hashes = new ulong[256]; hashes = new ulong[256];
startIndices = new int[hashes.Length]; startIndices = new int[hashes.Length + 1];
} }
public void Init(Board board) public void Init(Board board)
@ -30,10 +30,14 @@ namespace ChessChallenge.Chess
public void Push(ulong hash, bool reset) public void Push(ulong hash, bool reset)
{
// Check bounds just in case
if (count < hashes.Length)
{ {
hashes[count] = hash; hashes[count] = hash;
startIndices[count + 1] = reset ? count : startIndices[count];
}
count++; count++;
startIndices[count] = reset ? count - 1 : startIndices[count - 1];
} }
public void TryPop() public void TryPop()