m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js37
-rw-r--r--src/lexer.js1
-rw-r--r--src/parser.js1
3 files changed, 39 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index e96aca9..e580c9d 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -162,6 +162,42 @@ const again = (die1, die2) => {
}
}
+const againUnder = (die1, die2) => {
+ return () => {
+ const againOn = roll(die1)
+ let rolls = []
+ let rollAgain = []
+
+ const rollDie = (die) => {
+ const roll = die()
+
+ if (roll <= againOn) {
+ rollAgain.push(die)
+ }
+
+ let returnedOriginal = false
+ rolls.push(() => {
+ if (!returnedOriginal) {
+ returnedOriginal = true
+ return roll
+ } else {
+ return die()
+ }
+ })
+ }
+
+ die2().forEach(rollDie)
+
+ while (rollAgain.length > 0) {
+ const oldRollAgain = rollAgain
+ rollAgain = []
+ oldRollAgain.forEach(rollDie)
+ }
+
+ return rolls
+ }
+}
+
const threshold = (die1, die2) => {
return () => {
const cutoff = roll(die1)
@@ -193,4 +229,5 @@ exports.explodeUnder = explodeUnder
exports.keepHigh = keepHigh
exports.keepLow = keepLow
exports.again = again
+exports.againUnder = againUnder
exports.threshold = threshold
diff --git a/src/lexer.js b/src/lexer.js
index 7eb95b0..f33dc87 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -27,6 +27,7 @@ newLexemeType('e', 'e')
newLexemeType('K', 'K')
newLexemeType('k', 'k')
newLexemeType('A', 'A')
+newLexemeType('a', 'a')
newLexemeType('T', 'T')
const lex = (expressionString) => {
diff --git a/src/parser.js b/src/parser.js
index 124d686..f8e2a5b 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -65,6 +65,7 @@ newDieOperation('e')
newDieOperation('K')
newDieOperation('k')
newDieOperation('A')
+newDieOperation('a')
newDieOperation('T')
newInfix('bigPlus', 20, { type: 'add' })