diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-09-05 22:29:24 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-09-05 22:29:24 -0400 |
commit | 83983efa99d910a97a72fc8b00dd9d7eb8829368 (patch) | |
tree | 17ac7dbb2332bdc7a5005264c591e894e674b0cf /src | |
parent | fb5cf866c56184dd615e4b7ec5cf6ed1a4703903 (diff) |
Implement multiplicative bonuses
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 9 | ||||
-rw-r--r-- | src/lexer.js | 1 | ||||
-rw-r--r-- | src/parser.js | 1 |
3 files changed, 11 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js index 5a484b0..6351929 100644 --- a/src/dice.js +++ b/src/dice.js @@ -73,6 +73,14 @@ const bonusSubtract = (die1, die2) => { } } +const bonusMultiply = (die1, die2) => { + return () => { + return die1().map(die => { + return () => die() * roll(die2) + }) + } +} + const explode = (comparison, die1, die2) => { return () => { const explodeOn = roll(die1) @@ -216,6 +224,7 @@ exports.multiply = multiply exports.divide = divide exports.bonusAdd = bonusAdd exports.bonusSubtract = bonusSubtract +exports.bonusMultiply = bonusMultiply exports.negative = negative exports.explodeAbove = explodeAbove exports.explodeUnder = explodeUnder diff --git a/src/lexer.js b/src/lexer.js index 248a9b2..e700f87 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -22,6 +22,7 @@ newLexemeType('bigTimes', ' \\* ') newLexemeType('bigDivide', ' / ') newLexemeType('plus', '\\+') newLexemeType('minus', '-') +newLexemeType('times', '\\*') newLexemeType('(', '\\(') newLexemeType(')', '\\)') newLexemeType('E', 'E') diff --git a/src/parser.js b/src/parser.js index b1f6ebb..54dc0ae 100644 --- a/src/parser.js +++ b/src/parser.js @@ -75,6 +75,7 @@ newInfix('bigTimes', 23, { type: 'multiply' }) newInfix('bigDivide', 23, { type: 'divide' }) newInfix('plus', 25, { type: 'bonusAdd' }) newInfix('minus', 25, { type: 'bonusSubtract' }) +newInfix('times', 26, { type: 'bonusMultiply' }) newSymbol('minus', (parser) => { return { type: 'negative', |