From db74fae2b70b974ab37a8b555716f461f56e458a Mon Sep 17 00:00:00 2001 From: David Walker Date: Sun, 9 Mar 2025 16:16:24 -0700 Subject: [PATCH] Fix first-time Go initialization (#2012) Fixes #2010 It was intended that all the various codepaths call `resetAI()` to initialize the promise handling. However, when there is no savegame at all, `loadGo()` is not even called, so this is skipped, and the promises remain not-fully-initialized. This puts the initialization as part of the static construction, guaranteeing a fix. Tested all 3 scenarios in #2010, as well as two more: * Delete save, immediately "Find new subnet". * Play a move, save game, ensure IPvGO works on reload. * Play a move, save game *before the AI moves*, ensure that the AI plays different random moves on reload. --- src/Go/boardAnalysis/goAI.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Go/boardAnalysis/goAI.ts b/src/Go/boardAnalysis/goAI.ts index 5fc1174fe..9a3623d14 100644 --- a/src/Go/boardAnalysis/goAI.ts +++ b/src/Go/boardAnalysis/goAI.ts @@ -32,6 +32,9 @@ const playerPromises: Record = { [GoColor.black]: { nextTurn: Promise.resolve(gameOver), resolver: null }, [GoColor.white]: { nextTurn: Promise.resolve(gameOver), resolver: null }, }; +// The promises aren't in a fully working state until we do this. +// It is OK to reset the AI multiple times in a row. +resetAI(); export function getNextTurn(color: GoColor.black | GoColor.white): Promise { return playerPromises[color].nextTurn;