IPVGO: Correctly end game & winstreak if a cheat attempt critically fails (#2130)

This commit is contained in:
Michael Ficocelli
2025-05-11 15:02:56 -04:00
committed by GitHub
parent eea6733e3b
commit fe1fc8ba14
2 changed files with 16 additions and 2 deletions

View File

@@ -90,6 +90,20 @@ export function endGoGame(boardState: BoardState) {
Player.applyEntropy(Player.entropy);
}
/**
* Forcefully ends the game, resetting the winstreak (if any) and ending the game without applying node power bonuses.
* Used for critically failing a cheat attempt.
* @param boardState - the boardstate to reset
*/
export function forceEndGoGame(boardState: BoardState) {
resetWinstreak(boardState.ai, false);
boardState.previousPlayer = null;
Go.currentGame = boardState;
Go.previousGame = boardState;
resetAI(true);
GoEvents.emit();
}
/**
* Sets the winstreak to zero for the given opponent, and adds a loss
*/

View File

@@ -19,7 +19,7 @@ import {
simpleBoardFromBoard,
simpleBoardFromBoardString,
} from "../boardAnalysis/boardAnalysis";
import { endGoGame, getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring";
import { forceEndGoGame, getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring";
import { WHRNG } from "../../Casino/RNG";
import { getRecordKeys } from "../../Types/Record";
import { CalculateEffect, getEffectTypeForFaction } from "./effect";
@@ -505,7 +505,7 @@ export function determineCheatSuccess(
// If there have been prior cheat attempts, and the cheat fails, there is a 10% chance of instantly losing
else if (priorCheatCount && (ejectRngOverride ?? rng.random()) < 0.1 && state.ai !== GoOpponent.none) {
logger(`Cheat failed! You have been ejected from the subnet.`);
endGoGame(state);
forceEndGoGame(state);
return handleNextTurn(state, true);
} else {
// If the cheat fails, your turn is skipped