Quellcode durchsuchen

Add countOutcomeBalance - balance successes/fails

tags/v0.1.3
bertieb vor 3 Jahren
Ursprung
Commit
1fe526f1d5
1 geänderte Dateien mit 14 neuen und 0 gelöschten Zeilen
  1. +14
    -0
      dice.ts

+ 14
- 0
dice.ts Datei anzeigen

@@ -32,6 +32,7 @@ interface DiceResult {
olddice?: Array<number>;
reroll?: boolean;
outcome?: Outcomes;
balance?: number;

}

@@ -121,6 +122,18 @@ class Asphodice extends D10 {
return ((checkDice.filter(die => die >= this.successCutOff).length == 0));
}

countOutcomeBalance (resultDice: Array<number>): number{
// Return a positive / negative number representing
// the overall outcomes: each failure (eg < 6) is -1
// while each success (eg >= 6) is +1

// fun with ternary operators
return resultDice.reduce(
(acc: number, curr: number) =>
{ return (curr < this.successCutOff) ? acc - 1 : acc + 1 },
0);
}

roll (numToRoll: number): DiceResult {
let results: DiceResult = { total: 0, dice: [] };

@@ -172,6 +185,7 @@ class Asphodice extends D10 {
}
}

results.balance = this.countOutcomeBalance(results.dice);
results.total = results.dice.reduce((acc: number, curr: number) => acc + curr);
return results;
}


Laden…
Abbrechen
Speichern