m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-19 23:13:21 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-19 23:40:18 -0400
commit3fccdd3d61d96d3c979f72c7a9d9c26420ae3656 (patch)
treec2c8c5f5907eac91bef42d9026acd9d87554658c /src
parent3a5f09ac15642bbebf7351ec92ad2bee7f0b0acc (diff)
Implement exploding dice
Diffstat (limited to 'src')
-rw-r--r--src/dice.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/dice.js b/src/dice.js
index 213eda8..b60af68 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -43,7 +43,16 @@ const subtract = (die1, die2) => {
const explode = (die1, die2) => {
return () => {
- return die1()
+ const explodeOn = roll(die1)
+ return die2().map(die => () => {
+ let lastRoll = die()
+ let total = lastRoll
+ while (lastRoll >= explodeOn) {
+ lastRoll = die()
+ total += lastRoll
+ }
+ return total
+ })
}
}