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
+10
View File
@@ -79,3 +79,13 @@ export type OpponentStats = {
highestWinStreak: number;
favor: number;
};
export type SimpleOpponentStats = {
wins: number;
losses: number;
winStreak: number;
highestWinStreak: number;
favor: number;
bonusPercent: number;
bonusDescription: string;
};
+28 -2
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;
+1
View File
@@ -260,6 +260,7 @@ const go = {
getChains: 16,
getLiberties: 16,
getControlledEmptyNodes: 16,
getStats: 0,
},
cheat: {
getCheatSuccessChance: 1,
+4
View File
@@ -18,6 +18,7 @@ import {
getGameState,
getLiberties,
getOpponentNextMove,
getStats,
getValidMoves,
handlePassTurn,
makePlayerMove,
@@ -85,6 +86,9 @@ export function NetscriptGo(): InternalAPI<NSGo> {
getControlledEmptyNodes: () => () => {
return getControlledEmptyNodes();
},
getStats: () => () => {
return getStats();
},
},
cheat: {
getCheatSuccessChance: (ctx: NetscriptContext) => () => {
+33
View File
@@ -3949,6 +3949,17 @@ type GoOpponent =
| "Illuminati"
| "????????????";
/** @public */
type SimpleOpponentStats = {
wins: number;
losses: number;
winStreak: number;
highestWinStreak: number;
favor: number;
bonusPercent: number;
bonusDescription: string;
};
/**
* IPvGO api
* @public
@@ -4167,6 +4178,28 @@ export interface Go {
* (This is intentionally expensive; you can derive this info from just getBoardState() )
*/
getControlledEmptyNodes(): string[];
/**
* Displays the game history, captured nodes, and gained bonuses for each opponent you have played against.
*
* The details are keyed by opponent name, in this structure:
*
* <pre lang="javascript">
* {
* <OpponentName>: {
* wins: number,
* losses: number,
* winStreak: number,
* highestWinStreak: number,
* favor: number,
* bonusPercent: number,
* bonusDescription: string,
* }
* }
* </pre>
*
*/
getStats(): Partial<Record<GoOpponent, SimpleOpponentStats>>;
};
/**