m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 14:49:11 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 14:49:11 -0400
commita31c3a1fd44a37cf0fcfff8c1cc52792565247b3 (patch)
treedf238e311a87344e52faf587c6f2165cc4487e4b
parent56d36c9129292cd0dd0b5e79eea14d79a4219a94 (diff)
Implement bonusAdd
-rw-r--r--__tests__/dice.test.js63
-rw-r--r--src/dice.js9
2 files changed, 71 insertions, 1 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js
index 1be0744..6fb48a2 100644
--- a/__tests__/dice.test.js
+++ b/__tests__/dice.test.js
@@ -6,7 +6,8 @@ const {
subtract,
negative,
explode,
- keepHigh
+ keepHigh,
+ bonusAdd
} = require('../src/dice.js')
const defaultNumberRolls = 500
@@ -406,3 +407,63 @@ describe('keep', () => {
testDie(die, basicDieTestSpecs(1, 20))
})
})
+
+describe('bonusAdd', () => {
+ describe('1d20+3', () => {
+ const die = bonusAdd(d(constant(1), constant(20)), constant(3))
+ testDie(die, {
+ diceCount: 1,
+ average: {
+ average: 13.5
+ },
+ variance: {
+ variance: 33.25
+ },
+ bounds: {
+ low: 4,
+ high: 23,
+ expectLow: true,
+ expectHigh: true
+ }
+ })
+ })
+
+ describe('3d4+1', () => {
+ const die = bonusAdd(d(constant(3), constant(4)), constant(1))
+ testDie(die, {
+ diceCount: 3,
+ average: {
+ average: 10.5
+ },
+ variance: {
+ variance: 3.75
+ },
+ bounds: {
+ low: 6,
+ high: 15,
+ expectLow: true,
+ expectHigh: true
+ }
+ })
+ })
+
+ describe('2d6+1d6', () => {
+ const die = bonusAdd(d(constant(2), constant(6)),
+ d(constant(1), constant(6)))
+ testDie(die, {
+ diceCount: 2,
+ average: {
+ average: 14
+ },
+ variance: {
+ variance: 11.67
+ },
+ bounds: {
+ low: 4,
+ high: 24,
+ expectLow: false,
+ expectHigh: false
+ }
+ })
+ })
+})
diff --git a/src/dice.js b/src/dice.js
index 5e3b975..14addd4 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -75,6 +75,14 @@ const keepHigh = (die1, die2) => {
}
}
+const bonusAdd = (die1, die2) => {
+ return () => {
+ return die1().map(die => {
+ return () => die() + roll(die2)
+ })
+ }
+}
+
exports.pool = pool
exports.roll = roll
exports.constant = constant
@@ -84,3 +92,4 @@ exports.subtract = subtract
exports.negative = negative
exports.explode = explode
exports.keepHigh = keepHigh
+exports.bonusAdd = bonusAdd