BUGFIX: Ensure that IPvGO promises are initialized correctly on a new save and on fluming (#2032)

This commit is contained in:
Michael Ficocelli
2025-03-17 18:55:32 -04:00
committed by GitHub
parent 88fef7d8a3
commit 47b34c8563
5 changed files with 15 additions and 11 deletions
+7 -2
View File
@@ -27,7 +27,7 @@ type PlayerPromise = {
resolver: ((play?: Play) => void) | null;
};
const gameOver = { type: GoPlayType.gameOver, x: null, y: null } as const;
const gameOver: Play = { type: GoPlayType.gameOver, x: null, y: null } as const;
const playerPromises: Record<GoColor.black | GoColor.white, PlayerPromise> = {
[GoColor.black]: { nextTurn: Promise.resolve(gameOver), resolver: null },
[GoColor.white]: { nextTurn: Promise.resolve(gameOver), resolver: null },
@@ -40,6 +40,11 @@ export function getNextTurn(color: GoColor.black | GoColor.white): Promise<Play>
return playerPromises[color].nextTurn;
}
export function resetGoPromises(): void {
resetAI();
handleNextTurn().catch((error) => exceptionAlert(error, true));
}
/**
* Does common processing in response to a move being made.
*
@@ -51,7 +56,7 @@ export function getNextTurn(color: GoColor.black | GoColor.white): Promise<Play>
* handling and dispatches common events.
* @returns the nextTurn promise for the player who just moved
*/
export function handleNextTurn(boardState: BoardState, useOfflineCycles = true): Promise<Play> {
export function handleNextTurn(boardState: BoardState = Go.currentGame, useOfflineCycles = true): Promise<Play> {
const previousColor = boardState.previousPlayer;
if (previousColor === null) {
// The game is over. We shouldn't get here in most circumstances,