m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-23 21:26:01 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-23 21:26:01 -0400
commit5bb027bde84e0a8fdb01bfa680b511ad842498ef (patch)
tree50c5c31b11986927f165f14804376ed6506ca609 /src
parent51748970426496823600522f5cfda65240d6e6e8 (diff)
Implement threshold
Diffstat (limited to 'src')
-rw-r--r--src/dice.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index ef67edf..9bc53d7 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -147,6 +147,22 @@ const again = (die1, die2) => {
}
}
+const threshold = (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
@@ -161,3 +177,4 @@ exports.explode = explode
exports.keepHigh = keepHigh
exports.keepLow = keepLow
exports.again = again
+exports.threshold = threshold