import { Asphodice } from "./asphodice" import { Outcomes } from "./asphodice" import { DiceResult } from "./asphodice" interface ItemCount { item: string | number | Outcomes; count: number; } declare let ItemCountSet: Array; type EnumObject = { [K in T]?: number }; type outcomeCountObject = EnumObject; /** * Singleton-type class for all dice-statistic related needs */ export class RollStats { rerollCounts: { [rerolled: string]: number } = {}; totalCounts: { [total: string]: number } = {}; balanceCounts: { [balance: string]: number } = {}; outcomeCounts: outcomeCountObject = {}; diceCounts: { [dice: string]: number} = {}; numRolls = 100000; maxDice = 10; numDice = 4; constructor() { this.resetCounts(); } resetCounts(): void { // TODO: find out if there's a way to this // by iterating over members this.rerollCounts = { "true": 0, "false": 0 }; this.totalCounts = {}; this.balanceCounts = {}; this.outcomeCounts = { [Outcomes.Success]: 0, [Outcomes.Fail]: 0 } // TODO: others for (let i = 1; i <= 10; i++) { this.diceCounts[String(i)] = 0; } } doRolls(): void { let asphodice = new Asphodice(); // count rerolls, totals and outcome balances for (let i = 0; i < this.numRolls; i++) { let result = asphodice.roll(this.numDice) if (result.reroll) { this.rerollCounts.true += 1; } else { this.rerollCounts.false += 1; } let total = String(result.total); if (total in this.totalCounts) { this.totalCounts[total]++; } else { this.totalCounts[total] = 1; } let balance = String(result.balance); if (balance in this.balanceCounts) { this.balanceCounts[balance]++; } else { this.balanceCounts[balance] = 1; } if (result.outcome == Outcomes.Success) { let count = this.outcomeCounts[Outcomes.Success]; this.outcomeCounts[Outcomes.Success] = Number(count) + 1; } else if (result.outcome == Outcomes.Fail) { let count = this.outcomeCounts[Outcomes.Fail]; this.outcomeCounts[Outcomes.Fail] = Number(count) + 1; } // TODO: crits, once those are implemented for (let die of result.dice) { this.diceCounts[String(die)] += 1; } } } reportRolls(): string { var report = ""; return report; } } let rollstats = new RollStats(); rollstats.doRolls(); console.log(rollstats);