Parcourir la source

Initial rollstats (and add entry to tsconfig)

tags/v0.1.3
bertieb il y a 3 ans
Parent
révision
d4168b7a9a
2 fichiers modifiés avec 54 ajouts et 1 suppressions
  1. +53
    -0
      rollstats.ts
  2. +1
    -1
      tsconfig.json

+ 53
- 0
rollstats.ts Voir le fichier

@@ -0,0 +1,53 @@
import { Asphodice } from "./asphodice"
import { Outcomes } from "./asphodice"
import { DiceResult } from "./asphodice"

interface ItemCount {
item: string | number | Outcomes;
count: number;
}


declare let ItemCountSet: Array<ItemCount>;

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

let numRolls = 1000000;
let maxDice = 10;

for (let numDice = 1; numDice <= maxDice; numDice++) {
let asphodice = new Asphodice();
rerollCounts = { "true": 0, "false": 0 };
totalCounts = {};
balanceCounts = {};
// count rerolls, totals and outcome balances

for (let i = 0; i < numRolls; i++) {
let result = asphodice.roll(numDice)

if (result.reroll) {
rerollCounts.true += 1;
} else {
rerollCounts.false += 1;
}

let total = String(result.total);
if (total in totalCounts) {
totalCounts[total]++;
} else {
totalCounts[total] = 1;
}

let balance = String(result.balance);
if (balance in balanceCounts) {
balanceCounts[balance]++;
} else {
balanceCounts[balance] = 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);
}

+ 1
- 1
tsconfig.json Voir le fichier

@@ -67,5 +67,5 @@
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": "dice.ts"
"include": [ "dice.ts", "rollstats.ts" ]
}

Chargement…
Annuler
Enregistrer