Fix occasional crash on bot timeout during match

This commit is contained in:
Sebastian Lague 2023-07-23 19:40:34 +02:00
parent cc3f49319b
commit 1d2368295c

View file

@ -23,6 +23,7 @@ namespace ChessChallenge.Application
} }
// Game state // Game state
Random rng;
int gameID; int gameID;
bool isPlaying; bool isPlaying;
Board board; Board board;
@ -60,6 +61,7 @@ namespace ChessChallenge.Application
tokenCount = GetTokenCount(); tokenCount = GetTokenCount();
Warmer.Warm(); Warmer.Warm();
rng = new Random();
moveGenerator = new(); moveGenerator = new();
boardUI = new BoardUI(); boardUI = new BoardUI();
board = new Board(); board = new Board();
@ -77,7 +79,7 @@ namespace ChessChallenge.Application
{ {
// End any ongoing game // End any ongoing game
EndGame(GameResult.DrawByArbiter, log: false, autoStartNextBotMatch: false); EndGame(GameResult.DrawByArbiter, log: false, autoStartNextBotMatch: false);
gameID++; gameID = rng.Next();
// Stop prev task and create a new one // Stop prev task and create a new one
if (RunBotsOnSeparateThread) if (RunBotsOnSeparateThread)
@ -275,6 +277,7 @@ namespace ChessChallenge.Application
{ {
isPlaying = false; isPlaying = false;
isWaitingToPlayMove = false; isWaitingToPlayMove = false;
gameID = -1;
if (log) if (log)
{ {