diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 18:48:45 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 18:52:42 -0400 |
commit | 831e19699a8b604c81df999b743ac0ce4853f502 (patch) | |
tree | f6faff59d1cca1432421ddc7cee479f7eab5df9a /src | |
parent | 5e435ad92cb7ae3d05c54d9e35020580a0459ded (diff) |
Refactor
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 38 | ||||
-rw-r--r-- | src/parser.js | 4 |
2 files changed, 21 insertions, 21 deletions
diff --git a/src/dice.js b/src/dice.js index 58467c4..6f3b7da 100644 --- a/src/dice.js +++ b/src/dice.js @@ -41,6 +41,23 @@ const subtract = (die1, die2) => { } } +const bonusAdd = (die1, die2) => { + return () => { + return die1().map(die => { + return () => die() + roll(die2) + }) + } +} + +const bonusSubtract = (die1, die2) => { + const negative2 = negative(die2) + return () => { + return die1().map(die => { + return () => die() + roll(negative2) + }) + } +} + const explode = (die1, die2) => { return () => { const explodeOn = roll(die1) @@ -94,32 +111,15 @@ const keepLow = (die1, die2) => { } } -const bonusAdd = (die1, die2) => { - return () => { - return die1().map(die => { - return () => die() + roll(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 exports.d = d exports.add = add exports.subtract = subtract +exports.bonusAdd = bonusAdd +exports.bonusSubtract = bonusSubtract exports.negative = negative 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 344fb7d..a4665ac 100644 --- a/src/parser.js +++ b/src/parser.js @@ -57,7 +57,7 @@ newSymbol('d', (parser) => { return { type: 'd', left: { type: 'constant', value: 1 }, - right: parser.expression(29) + right: parser.expression(dieBindingPower - 1) } }) newDieOperation('E') @@ -65,9 +65,9 @@ newDieOperation('K') newDieOperation('k') newInfix('bigPlus', 20, { type: 'add' }) +newInfix('bigMinus', 20, { type: 'subtract' }) newInfix('plus', 25, { type: 'bonusAdd' }) newInfix('minus', 25, { type: 'bonusSubtract' }) -newInfix('bigMinus', 20, { type: 'subtract' }) newSymbol('minus', (parser) => { return { type: 'negative', |