Browse Source

'Cancel out' reroll pairs when determining re-roll

tags/v0.1.3
bertieb 3 years ago
parent
commit
0f1fb9ef3b
1 changed files with 10 additions and 7 deletions
  1. +10
    -7
      dice.ts

+ 10
- 7
dice.ts View File

@@ -306,15 +306,18 @@ export class Asphodice extends D10 {
* - all below cutoff
*/
rerollNeeded(resultDice: Array<number>): boolean{
// 'Cancel out' matching re-roll dice
let cancelledDice = this.cancelRerollDice(resultDice);

// 1. if no re-rolls we can finish here
if (!(resultDice.includes(this.passCrit) || resultDice.includes(this.failCrit))) {
if (!(cancelledDice.includes(this.passCrit) || resultDice.includes(this.failCrit))) {
// results.total = results.dice.reduce((acc: number, curr: number) => acc + curr);
return false;
}

// count successes and fails
let rerollGood = countOccurrencesOfNumber(resultDice, this.passCrit);
let rerollBad = countOccurrencesOfNumber(resultDice, this.failCrit);
let rerollGood = countOccurrencesOfNumber(cancelledDice, this.passCrit);
let rerollBad = countOccurrencesOfNumber(cancelledDice, this.failCrit);

// 2. only reroll if they don't cancel each other out
if (rerollGood == rerollBad) {
@@ -324,11 +327,11 @@ export class Asphodice extends D10 {
}

// 3. If all dice are above/below cutoff we don't need to reroll
if (this.allAboveCutOff(resultDice)) {
console.log("All above cutoff, auto-success", resultDice);
if (this.allAboveCutOff(cancelledDice)) {
console.log("All above cutoff, auto-success", cancelledDice);
return false;
} else if (this.allBelowCutOff(resultDice)) {
console.log("All below cutoff, auto-fail", resultDice);
} else if (this.allBelowCutOff(cancelledDice)) {
console.log("All below cutoff, auto-fail", cancelledDice);
return false;
}



Loading…
Cancel
Save