Skip to content

tphummel/node-craps

Repository files navigation

node-craps

Github Workflow Status

🎲🎲 craps simulator πŸ’΅

architecture overview

                        +-----------+
                        | hands.js  | CLI entry point
                        +-----------+
                               |
                               v
  +-----------------------------------------------------+
  | playHand() (index.js)                               |
  |-----------------------------------------------------|
  | β€’ apply betting strategy from betting.js            |
  | β€’ roll dice via shoot()/rollD6                      |
  | β€’ settle bets with settle.all() from settle.js      |
  +-----------------------------------------------------+
           |                |                    |
           v                v                    v
      +---------+     +--------------+     +--------------+
      | shoot()  |     | betting.js   |     |  settle.js   |
      | rollD6   |     | strategies   |     | payout logic |
      +---------+     +--------------+     +--------------+

simulate a hand

➜  node hands.js 1

Simulating 1 Craps Hand(s)

Dice Roll Distribution
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ Values β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    2    β”‚   0    β”‚
β”‚    3    β”‚   0    β”‚
β”‚    4    β”‚   0    β”‚
β”‚    5    β”‚   2    β”‚
β”‚    6    β”‚   2    β”‚
β”‚    7    β”‚   1    β”‚
β”‚    8    β”‚   3    β”‚
β”‚    9    β”‚   3    β”‚
β”‚   10    β”‚   1    β”‚
β”‚   11    β”‚   2    β”‚
β”‚   12    β”‚   0    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Session Summary
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    (index)     β”‚ Values β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   handCount    β”‚   1    β”‚
β”‚   rollCount    β”‚   14   β”‚
β”‚   pointsSet    β”‚   3    β”‚
β”‚   pointsWon    β”‚   2    β”‚
β”‚  comeOutWins   β”‚   0    β”‚
β”‚ comeOutLosses  β”‚   0    β”‚
β”‚ netComeOutWins β”‚   0    β”‚
β”‚    neutrals    β”‚   8    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Hands

Hand: 1
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ die1 β”‚ die2 β”‚ diceSum β”‚   result    β”‚ isComeOut β”‚ point β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚    0    β”‚  3   β”‚  6   β”‚    9    β”‚ 'point set' β”‚   false   β”‚   9   β”‚
β”‚    1    β”‚  4   β”‚  5   β”‚    9    β”‚ 'point win' β”‚   true    β”‚       β”‚
β”‚    2    β”‚  3   β”‚  5   β”‚    8    β”‚ 'point set' β”‚   false   β”‚   8   β”‚
β”‚    3    β”‚  3   β”‚  6   β”‚    9    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚    4    β”‚  5   β”‚  5   β”‚   10    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚    5    β”‚  3   β”‚  5   β”‚    8    β”‚ 'point win' β”‚   true    β”‚       β”‚
β”‚    6    β”‚  2   β”‚  6   β”‚    8    β”‚ 'point set' β”‚   false   β”‚   8   β”‚
β”‚    7    β”‚  2   β”‚  3   β”‚    5    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚    8    β”‚  1   β”‚  4   β”‚    5    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚    9    β”‚  5   β”‚  6   β”‚   11    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚   10    β”‚  2   β”‚  4   β”‚    6    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚   11    β”‚  1   β”‚  5   β”‚    6    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚   12    β”‚  5   β”‚  6   β”‚   11    β”‚  'neutral'  β”‚   false   β”‚   8   β”‚
β”‚   13    β”‚  3   β”‚  4   β”‚    7    β”‚ 'seven out' β”‚   true    β”‚       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

use as a module

const simulateHands = require('./hands.js')
const result = simulateHands(1)
console.log(result.sessionSummary)

monte carlo simulation

Run many trials to see how a strategy performs over time.

$ node monte-carlo.js 2 5 500 5 3-4-5
Running 2 trials with 5 hand(s) each
[table rules] minimum bet: $5, odds 3-4-5

Trial Results
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ trial β”‚ balance β”‚ rolls β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0       β”‚ 1     β”‚ 614     β”‚ 65    β”‚
β”‚ 1       β”‚ 2     β”‚ 416     β”‚ 25    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

Final Balance Summary
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ stat   β”‚ value  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0       β”‚ min    β”‚ 416    β”‚
β”‚ 1       β”‚ p1     β”‚ 416    β”‚
β”‚ 2       β”‚ p5     β”‚ 416    β”‚
β”‚ 3       β”‚ p10    β”‚ 416    β”‚
β”‚ 4       β”‚ p25    β”‚ 416    β”‚
β”‚ 5       β”‚ p50    β”‚ 416    β”‚
β”‚ 6       β”‚ mean   β”‚ 515    β”‚
β”‚ 7       β”‚ p75    β”‚ 614    β”‚
β”‚ 8       β”‚ p90    β”‚ 614    β”‚
β”‚ 9       β”‚ p95    β”‚ 614    β”‚
β”‚ 10      β”‚ p99    β”‚ 614    β”‚
β”‚ 11      β”‚ max    β”‚ 614    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
stdDev: 140.01
95% CI: [320.96, 709.04]

Roll Count Summary
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ stat   β”‚ value  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0       β”‚ min    β”‚ 25     β”‚
β”‚ 1       β”‚ p1     β”‚ 25     β”‚
β”‚ 2       β”‚ p5     β”‚ 25     β”‚
β”‚ 3       β”‚ p10    β”‚ 25     β”‚
β”‚ 4       β”‚ p25    β”‚ 25     β”‚
β”‚ 5       β”‚ p50    β”‚ 25     β”‚
β”‚ 6       β”‚ mean   β”‚ 45     β”‚
β”‚ 7       β”‚ p75    β”‚ 65     β”‚
β”‚ 8       β”‚ p90    β”‚ 65     β”‚
β”‚ 9       β”‚ p95    β”‚ 65     β”‚
β”‚ 10      β”‚ p99    β”‚ 65     β”‚
β”‚ 11      β”‚ max    β”‚ 65     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
stdDev: 28.28
95% CI: [5.80, 84.20]

The standard deviation shows how widely the trials vary around the mean. Roughly 68% of results will fall within one standard deviation, 95% within two, and 99.7% within three. The 95% confidence interval is a range that is expected to contain the true mean in 95% of repeated samples.

table rules

playHand accepts a rules object that controls minimum bets and odds limits. You can now also customize which numbers win or lose on the come out roll.

const rules = {
  minBet: 5,
  maxOddsMultiple: { /* ... */ },
  comeOutWin: [7, 11],
  comeOutLoss: [2, 3, 12] // default
}

playHand also accepts a balance option to specify the starting amount for a hand. It defaults to 0.

For example, to make boxcars (12) a come out win instead of a loss:

const rules = {
  comeOutLoss: [2, 3],
  comeOutWin: [7, 11, 12]
}

what? why?

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.

dev

git clone [email protected]:tphummel/node-craps.git
cd node-craps
npm i
npm t

About

🎲🎲 craps simulator πŸ’΅

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published