Skip to content

Commit 1eb4361

Browse files
authored
Merge pull request #6 from tphummel/codex/add-support-for-additional-table-rules
2 parents abc529b + 7c33a71 commit 1eb4361

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ Hand: 1
6565
└─────────┴──────┴──────┴─────────┴─────────────┴───────────┴───────┘
6666
```
6767

68+
## table rules
69+
70+
`playHand` accepts a `rules` object that controls minimum bets and odds limits.
71+
You can now also customize which numbers win or lose on the come out roll.
72+
73+
```js
74+
const rules = {
75+
minBet: 5,
76+
maxOddsMultiple: { /* ... */ },
77+
comeOutWin: [7, 11],
78+
comeOutLoss: [2, 3, 12] // default
79+
}
80+
```
81+
6882
## what? why?
6983

7084
I like to play craps sometimes. I have a handful of strategies I like to play. It is time consuming to play in an app. I'd like to play 5, 50, 500 hands very fast using various strategies. Which strategies are best is well understood, the variability comes in with how aggressive your strategies are and the level of risk you assume at any given moment. And of course the dice outcomes and their deviation from long term probabilities and how they interact with the strategies you employ is the fun part. This simulator lets me scratch my craps itch very quickly.

index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ function rollD6 () {
77
return 1 + Math.floor(Math.random() * 6)
88
}
99

10-
function shoot (before, dice) {
10+
const defaultRules = {
11+
comeOutLoss: [2, 3, 12],
12+
comeOutWin: [7, 11]
13+
}
14+
15+
function shoot (before, dice, rules = defaultRules) {
16+
rules = Object.assign({}, defaultRules, rules)
1117
const sortedDice = dice.sort()
1218

1319
const after = {
@@ -19,10 +25,10 @@ function shoot (before, dice) {
1925
// game logic based on: https://github.com/tphummel/dice-collector/blob/master/PyTom/Dice/logic.py
2026

2127
if (before.isComeOut) {
22-
if ([2, 3, 12].indexOf(after.diceSum) !== -1) {
28+
if (rules.comeOutLoss.includes(after.diceSum)) {
2329
after.result = 'comeout loss'
2430
after.isComeOut = true
25-
} else if ([7, 11].indexOf(after.diceSum) !== -1) {
31+
} else if (rules.comeOutWin.includes(after.diceSum)) {
2632
after.result = 'comeout win'
2733
after.isComeOut = true
2834
} else {
@@ -65,7 +71,8 @@ function playHand ({ rules, bettingStrategy, roll = rollD6 }) {
6571

6672
hand = shoot(
6773
hand,
68-
[roll(), roll()]
74+
[roll(), roll()],
75+
rules
6976
)
7077

7178
if (process.env.DEBUG) console.log(`[roll] ${hand.result} (${hand.diceSum})`)
@@ -88,5 +95,6 @@ module.exports = {
8895
rollD6,
8996
shoot,
9097
playHand,
91-
betting
98+
betting,
99+
defaultRules
92100
}

index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,23 @@ tap.test('comeout', function (suite) {
199199
suite.end()
200200
})
201201

202+
tap.test('comeout with custom rules', (t) => {
203+
const handState = {
204+
isComeOut: true
205+
}
206+
207+
const rules = {
208+
comeOutLoss: [2, 3],
209+
comeOutWin: [7, 11, 12]
210+
}
211+
212+
const result = lib.shoot(handState, [6, 6], rules)
213+
t.equal(result.result, 'comeout win')
214+
t.equal(result.isComeOut, true)
215+
216+
t.end()
217+
})
218+
202219
tap.test('point set', (suite) => {
203220
suite.test('neutral 2', (t) => {
204221
const handState = {

0 commit comments

Comments
 (0)