diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-30 16:36:40 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-30 16:36:40 -0400 |
commit | a7b971ef64f09a21902f34b6078b01d78dcf73e7 (patch) | |
tree | f3ed0e97fe3f31e8c7ca58e18a5835290e66c755 /src | |
parent | 5b77a409c912f7251da8c170bd4a3aa8826d989b (diff) |
Implement threshold under
Diffstat (limited to 'src')
-rw-r--r-- | src/dice.js | 16 | ||||
-rw-r--r-- | src/lexer.js | 1 | ||||
-rw-r--r-- | src/parser.js | 1 |
3 files changed, 18 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js index e580c9d..53d337d 100644 --- a/src/dice.js +++ b/src/dice.js @@ -214,6 +214,21 @@ const threshold = (die1, die2) => { } } +const thresholdLow = (die1, die2) => { + return () => { + const cutoff = roll(die1) + + return die2().map(die => { + return () => { + if (die() <= cutoff) { + return 1 + } else { + return 0 + } + } + }) + } +} exports.pool = pool exports.roll = roll @@ -231,3 +246,4 @@ exports.keepLow = keepLow exports.again = again exports.againUnder = againUnder exports.threshold = threshold +exports.thresholdLow = thresholdLow diff --git a/src/lexer.js b/src/lexer.js index f33dc87..ba3d3a5 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -29,6 +29,7 @@ newLexemeType('k', 'k') newLexemeType('A', 'A') newLexemeType('a', 'a') newLexemeType('T', 'T') +newLexemeType('t', 't') const lex = (expressionString) => { let lexemes = [] diff --git a/src/parser.js b/src/parser.js index f8e2a5b..adb4b9b 100644 --- a/src/parser.js +++ b/src/parser.js @@ -67,6 +67,7 @@ newDieOperation('k') newDieOperation('A') newDieOperation('a') newDieOperation('T') +newDieOperation('t') newInfix('bigPlus', 20, { type: 'add' }) newInfix('bigMinus', 20, { type: 'subtract' }) |