diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 18:01:48 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 18:15:15 -0400 |
commit | 1426322eb4898cd49310c1dc30cdfc8ad8e73402 (patch) | |
tree | c22776bb6af5180d41b90d0ceb7c06c03c66dd9b /src | |
parent | 12a632d2772da84043d4335eeabbca505efd760f (diff) |
Parse negative bonuses
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 10 | ||||
-rw-r--r-- | src/parser.js | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js index becf7dc..58467c4 100644 --- a/src/dice.js +++ b/src/dice.js @@ -102,6 +102,15 @@ const bonusAdd = (die1, die2) => { } } +const bonusSubtract = (die1, die2) => { + const negative2 = negative(die2) + return () => { + return die1().map(die => { + return () => die() + roll(negative2) + }) + } +} + exports.pool = pool exports.roll = roll exports.constant = constant @@ -113,3 +122,4 @@ exports.explode = explode exports.keepHigh = keepHigh exports.keepLow = keepLow exports.bonusAdd = bonusAdd +exports.bonusSubtract = bonusSubtract diff --git a/src/parser.js b/src/parser.js index 48de2ab..244cdd1 100644 --- a/src/parser.js +++ b/src/parser.js @@ -66,6 +66,7 @@ newDieOperation('k') newInfix('bigPlus', 20, { type: 'add' }) newInfix('plus', 20, { type: 'bonusAdd' }) +newInfix('minus', 20, { type: 'bonusSubtract' }) newInfix('bigMinus', 20, { type: 'subtract' }) newSymbol('minus', (parser) => { return { |