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

View File

@@ -2,7 +2,7 @@ import type { BoardState, OpponentStats } from "./Types";
import type { GoOpponent } from "@enums"; import type { GoOpponent } from "@enums";
import { getRecordKeys, PartialRecord } from "../Types/Record"; import { getRecordKeys, PartialRecord } from "../Types/Record";
import { resetAI } from "./boardAnalysis/goAI"; import { resetGoPromises } from "./boardAnalysis/goAI";
import { getNewBoardState } from "./boardState/boardState"; import { getNewBoardState } from "./boardState/boardState";
import { EventEmitter } from "../utils/EventEmitter"; import { EventEmitter } from "../utils/EventEmitter";
import { newOpponentStats } from "./Constants"; import { newOpponentStats } from "./Constants";
@@ -20,10 +20,10 @@ export class GoObject {
} }
} }
prestigeSourceFile() { prestigeSourceFile() {
resetAI();
this.previousGame = null; this.previousGame = null;
this.currentGame = getNewBoardState(7); this.currentGame = getNewBoardState(7);
this.stats = {}; this.stats = {};
resetGoPromises();
} }
/** /**

View File

@@ -27,7 +27,7 @@ type PlayerPromise = {
resolver: ((play?: Play) => void) | null; 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> = { const playerPromises: Record<GoColor.black | GoColor.white, PlayerPromise> = {
[GoColor.black]: { nextTurn: Promise.resolve(gameOver), resolver: null }, [GoColor.black]: { nextTurn: Promise.resolve(gameOver), resolver: null },
[GoColor.white]: { 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; 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. * 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. * handling and dispatches common events.
* @returns the nextTurn promise for the player who just moved * @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; const previousColor = boardState.previousPlayer;
if (previousColor === null) { if (previousColor === null) {
// The game is over. We shouldn't get here in most circumstances, // The game is over. We shouldn't get here in most circumstances,

View File

@@ -10,7 +10,7 @@ import {
passTurn, passTurn,
updateCaptures, updateCaptures,
} from "../boardState/boardState"; } from "../boardState/boardState";
import { getNextTurn, handleNextTurn, resetAI } from "../boardAnalysis/goAI"; import { getNextTurn, handleNextTurn, resetGoPromises } from "../boardAnalysis/goAI";
import { import {
evaluateIfMoveIsValid, evaluateIfMoveIsValid,
getControlledSpace, getControlledSpace,
@@ -22,7 +22,6 @@ import { endGoGame, getOpponentStats, getScore, resetWinstreak } from "../boardA
import { WHRNG } from "../../Casino/RNG"; import { WHRNG } from "../../Casino/RNG";
import { getRecordKeys } from "../../Types/Record"; import { getRecordKeys } from "../../Types/Record";
import { CalculateEffect, getEffectTypeForFaction } from "./effect"; import { CalculateEffect, getEffectTypeForFaction } from "./effect";
import { exceptionAlert } from "../../utils/helpers/exceptionAlert";
import { newOpponentStats } from "../Constants"; import { newOpponentStats } from "../Constants";
/** /**
@@ -342,9 +341,8 @@ export function resetBoardState(
resetWinstreak(oldBoardState.ai, false); resetWinstreak(oldBoardState.ai, false);
} }
resetAI();
Go.currentGame = getNewBoardState(boardSize, opponent, true); Go.currentGame = getNewBoardState(boardSize, opponent, true);
handleNextTurn(Go.currentGame).catch((error) => exceptionAlert(error)); resetGoPromises();
logger(`New game started: ${opponent}, ${boardSize}x${boardSize}`); logger(`New game started: ${opponent}, ${boardSize}x${boardSize}`);
return simpleBoardFromBoard(Go.currentGame.board); return simpleBoardFromBoard(Go.currentGame.board);
} }

View File

@@ -18,7 +18,7 @@ import { GoScoreModal } from "./GoScoreModal";
import { GoGameboard } from "./GoGameboard"; import { GoGameboard } from "./GoGameboard";
import { GoSubnetSearch } from "./GoSubnetSearch"; import { GoSubnetSearch } from "./GoSubnetSearch";
import { CorruptableText } from "../../ui/React/CorruptableText"; import { CorruptableText } from "../../ui/React/CorruptableText";
import { handleNextTurn, resetAI } from "../boardAnalysis/goAI"; import { handleNextTurn, resetGoPromises } from "../boardAnalysis/goAI";
import { GoScoreExplanation } from "./GoScoreExplanation"; import { GoScoreExplanation } from "./GoScoreExplanation";
import { exceptionAlert } from "../../utils/helpers/exceptionAlert"; import { exceptionAlert } from "../../utils/helpers/exceptionAlert";
@@ -133,9 +133,8 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
resetWinstreak(boardState.ai, false); resetWinstreak(boardState.ai, false);
} }
resetAI();
Go.currentGame = getNewBoardState(newBoardSize, newOpponent, true); Go.currentGame = getNewBoardState(newBoardSize, newOpponent, true);
handleNextTurn(Go.currentGame).catch((error) => exceptionAlert(error)); resetGoPromises();
} }
function getPriorMove() { function getPriorMove() {

View File

@@ -47,6 +47,7 @@ import { SaveData } from "./types";
import { Go } from "./Go/Go"; import { Go } from "./Go/Go";
import { EventEmitter } from "./utils/EventEmitter"; import { EventEmitter } from "./utils/EventEmitter";
import { Companies } from "./Company/Companies"; import { Companies } from "./Company/Companies";
import { resetGoPromises } from "./Go/boardAnalysis/goAI";
declare global { declare global {
// This property is only available in the dev build // This property is only available in the dev build
@@ -391,6 +392,7 @@ const Engine: {
Player.init(); Player.init();
initForeignServers(Player.getHomeComputer()); initForeignServers(Player.getHomeComputer());
Player.reapplyAllAugmentations(); Player.reapplyAllAugmentations();
resetGoPromises();
// Start interactive tutorial // Start interactive tutorial
iTutorialStart(); iTutorialStart();