IPVGO: Provide API for getting game stats per opponent (#1255)

Give users access to wins, losses, stat bonuses, and favor gained
This commit is contained in:
Michael Ficocelli
2024-05-10 04:57:03 -04:00
committed by GitHub
parent 35c32e2871
commit b53c35126e
9 changed files with 100 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import type { BoardState, Play } from "../Types";
import { BoardState, Play, SimpleOpponentStats } from "../Types";
import { Player } from "@player";
import { AugmentationName, GoColor, GoOpponent, GoPlayType, GoValidity } from "@enums";
@@ -11,8 +11,10 @@ import {
getControlledSpace,
simpleBoardFromBoard,
} from "../boardAnalysis/boardAnalysis";
import { getScore, resetWinstreak } from "../boardAnalysis/scoring";
import { getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring";
import { WHRNG } from "../../Casino/RNG";
import { getRecordKeys } from "../../Types/Record";
import { CalculateEffect, getEffectTypeForFaction } from "./effect";
/**
* Check the move based on the current settings
@@ -362,6 +364,30 @@ export function resetBoardState(
return simpleBoardFromBoard(Go.currentGame.board);
}
/**
* Retrieve and clean up stats for each opponent played against
*/
export function getStats() {
const statDetails: Partial<Record<GoOpponent, SimpleOpponentStats>> = {};
for (const opponent of getRecordKeys(Go.stats)) {
const details = getOpponentStats(opponent);
const nodePower = getOpponentStats(opponent).nodePower;
const effectPercent = (CalculateEffect(nodePower, opponent) - 1) * 100;
const effectDescription = getEffectTypeForFaction(opponent);
statDetails[opponent] = {
wins: details.wins,
losses: details.losses,
winStreak: details.winStreak,
highestWinStreak: details.highestWinStreak,
favor: details.favor,
bonusPercent: effectPercent,
bonusDescription: effectDescription,
};
}
return statDetails;
}
/** Validate singularity access by throwing an error if the player does not have access. */
export function checkCheatApiAccess(error: (s: string) => void): void {
const hasSourceFile = Player.sourceFileLvl(14) > 1;