Browse Source

Add individual dice and outcome counts

tags/v0.1.3
bertieb 3 years ago
parent
commit
250695b004
1 changed files with 27 additions and 0 deletions
  1. +27
    -0
      rollstats.ts

+ 27
- 0
rollstats.ts View File

@@ -9,10 +9,16 @@ interface ItemCount {


declare let ItemCountSet: Array<ItemCount>;
type EnumObject<T extends string> = { [K in T]?: number };
type outcomeCountObject = EnumObject<Outcomes>;


let rerollCounts: { [rerolled: string]: number };
let totalCounts: { [total: string]: number };
let balanceCounts: { [balance: string]: number };
let outcomeCounts: outcomeCountObject = {};

let diceCounts: { [dice: string]: number} = {};

let numRolls = 1000000;
let maxDice = 10;
@@ -22,6 +28,12 @@ for (let numDice = 1; numDice <= maxDice; numDice++) {
rerollCounts = { "true": 0, "false": 0 };
totalCounts = {};
balanceCounts = {};
outcomeCounts = { [Outcomes.Success]: 0, [Outcomes.Fail]: 0 } // TODO: others
// reset dice counts
for (let i = 1; i <= 10; i++) {
diceCounts[String(i)] = 0;
}

// count rerolls, totals and outcome balances

for (let i = 0; i < numRolls; i++) {
@@ -46,8 +58,23 @@ for (let numDice = 1; numDice <= maxDice; numDice++) {
} else {
balanceCounts[balance] = 1;
}

if (result.outcome == Outcomes.Success) {
let count = outcomeCounts[Outcomes.Success];
outcomeCounts[Outcomes.Success] = Number(count) + 1;
} else if (result.outcome == Outcomes.Fail) {
let count = outcomeCounts[Outcomes.Fail];
outcomeCounts[Outcomes.Fail] = Number(count) + 1;
} // TODO: crits, once those are implemented

for (let die of result.dice) {
diceCounts[String(die)] += 1;
}

}
console.log(numRolls, "rolls,", numDice, "dice. Reroll counts:", rerollCounts);
console.log(numRolls, "rolls,", numDice, "dice. Total counts:", totalCounts);
console.log(numRolls, "rolls,", numDice, "dice. Balance counts:", balanceCounts);
console.log(numRolls, "rolls,", numDice, "dice. Dice counts:", diceCounts);
console.log(numRolls, "rolls,", numDice, "dice. Outcome counts:", outcomeCounts);
}

Loading…
Cancel
Save