m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-05 22:43:38 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-09-05 22:43:38 -0400
commite7383cc38bf2182e5ab95f30d639fe4a0317fd51 (patch)
tree5d2ebb3304dc5e7ba16e360c7940e4af4e49b272 /src
parent83983efa99d910a97a72fc8b00dd9d7eb8829368 (diff)
Implement bonus division
Diffstat (limited to 'src')
-rw-r--r--src/dice.js9
-rw-r--r--src/lexer.js1
-rw-r--r--src/parser.js1
3 files changed, 11 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index 6351929..0197f25 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -81,6 +81,14 @@ const bonusMultiply = (die1, die2) => {
}
}
+const bonusDivide = (die1, die2) => {
+ return () => {
+ return die1().map(die => {
+ return () => Math.floor(die() / roll(die2))
+ })
+ }
+}
+
const explode = (comparison, die1, die2) => {
return () => {
const explodeOn = roll(die1)
@@ -225,6 +233,7 @@ exports.divide = divide
exports.bonusAdd = bonusAdd
exports.bonusSubtract = bonusSubtract
exports.bonusMultiply = bonusMultiply
+exports.bonusDivide = bonusDivide
exports.negative = negative
exports.explodeAbove = explodeAbove
exports.explodeUnder = explodeUnder
diff --git a/src/lexer.js b/src/lexer.js
index e700f87..6b75129 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -23,6 +23,7 @@ newLexemeType('bigDivide', ' / ')
newLexemeType('plus', '\\+')
newLexemeType('minus', '-')
newLexemeType('times', '\\*')
+newLexemeType('divide', '/')
newLexemeType('(', '\\(')
newLexemeType(')', '\\)')
newLexemeType('E', 'E')
diff --git a/src/parser.js b/src/parser.js
index 54dc0ae..acae9ad 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -76,6 +76,7 @@ newInfix('bigDivide', 23, { type: 'divide' })
newInfix('plus', 25, { type: 'bonusAdd' })
newInfix('minus', 25, { type: 'bonusSubtract' })
newInfix('times', 26, { type: 'bonusMultiply' })
+newInfix('divide', 26, { type: 'bonusDivide' })
newSymbol('minus', (parser) => {
return {
type: 'negative',