Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions betting.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,65 @@ function minPassLineOnly (opts) {
return bets
}

function minPassLineMaxOdds (opts) {
const bets = minPassLineOnly(opts)
const { rules, hand } = opts
const makeNewPassOddsBet = hand.isComeOut === false && !bets?.pass?.odds
if (process.env.DEBUG) console.log(`[decision] make a new pass odds bet?: ${makeNewPassOddsBet}`)

if (makeNewPassOddsBet) {
const oddsAmount = rules.maxOddsMultiple[hand.point] * bets.pass.line.amount
if (process.env.DEBUG) console.log(`[action] make pass odds bet $${oddsAmount}`)
bets.pass.odds = {
amount: oddsAmount
function lineMaxOdds ({
rules,
bets: existingBets,
point,
shouldMakeLineBet,
shouldMakeOddsBet,
betKey = 'pass'
}) {
const bets = Object.assign({ new: 0 }, existingBets)

bets[betKey] = bets[betKey] || {}

const makeLineBet = shouldMakeLineBet && !bets[betKey].line
if (process.env.DEBUG) {
console.log(`[decision] make a new ${betKey} line bet?: ${makeLineBet}`)
}

if (makeLineBet) {
const newLineBet = { amount: rules.minBet }
bets[betKey].line = newLineBet
bets.new += newLineBet.amount
if (process.env.DEBUG) {
console.log(`[action] make ${betKey} line bet $${newLineBet.amount}`)
}
} else if (process.env.DEBUG) {
console.log(`[action] ${betKey} line bet unchanged`)
}

const makeOddsBet = shouldMakeOddsBet && bets[betKey].line && !bets[betKey].odds
if (process.env.DEBUG) {
console.log(`[decision] make a new ${betKey} odds bet?: ${makeOddsBet}`)
}

if (makeOddsBet) {
const oddsAmount = rules.maxOddsMultiple[point] * bets[betKey].line.amount
bets[betKey].odds = { amount: oddsAmount }
bets.new += oddsAmount
} else {
if (process.env.DEBUG) console.log('[decision] skip new pass odds bet')
if (process.env.DEBUG) {
console.log(`[action] make ${betKey} odds bet $${oddsAmount}`)
}
} else if (process.env.DEBUG) {
console.log(`[decision] skip new ${betKey} odds bet`)
}

return bets
}

function minPassLineMaxOdds (opts) {
const { rules, hand } = opts
return lineMaxOdds({
rules,
bets: opts.bets,
point: hand.point,
shouldMakeLineBet: hand.isComeOut,
shouldMakeOddsBet: hand.isComeOut === false,
betKey: 'pass'
})
}

function placeSixEight (opts) {
const { rules, bets: existingBets = {}, hand } = opts
const bets = Object.assign({ new: 0 }, existingBets)
Expand Down Expand Up @@ -108,8 +147,10 @@ function minPassLineMaxOddsPlaceSixEight (opts) {

module.exports = {
minPassLineOnly,
lineMaxOdds,
minPassLineMaxOdds,
placeSixEight,
placeSixEightUnlessPoint,
minPassLinePlaceSixEight,
minPassLineMaxOddsPlaceSixEight
}
62 changes: 62 additions & 0 deletions betting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,68 @@ tap.test('minPassLineOnly: bet exists, point set', (t) => {
t.end()
})

tap.test('lineMaxOdds: new line bet only', (t) => {
const rules = {
minBet: 5,
maxOddsMultiple: {
4: 3,
5: 4,
6: 5,
8: 5,
9: 4,
10: 3
}
}

const hand = { isComeOut: true }

const updatedBets = lib.lineMaxOdds({
rules,
hand,
shouldMakeLineBet: true,
shouldMakeOddsBet: false,
point: 4,
betKey: 'pass'
})

t.equal(updatedBets.pass.line.amount, rules.minBet)
t.equal(updatedBets.new, rules.minBet)

t.end()
})

tap.test('lineMaxOdds: add odds to existing line bet', (t) => {
const rules = {
minBet: 5,
maxOddsMultiple: {
4: 3,
5: 4,
6: 5,
8: 5,
9: 4,
10: 3
}
}

const hand = { isComeOut: false, point: 6 }
const bets = { pass: { line: { amount: rules.minBet } } }

const updatedBets = lib.lineMaxOdds({
rules,
hand,
bets,
shouldMakeLineBet: false,
shouldMakeOddsBet: true,
point: hand.point,
betKey: 'pass'
})

t.equal(updatedBets.pass.odds.amount, rules.maxOddsMultiple['6'] * rules.minBet)
t.equal(updatedBets.new, updatedBets.pass.odds.amount)

t.end()
})

tap.test('minPassLineMaxOdds: make new bet upon establishing point', (t) => {
const rules = {
minBet: 5,
Expand Down
4 changes: 2 additions & 2 deletions hands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const { playHand } = require('./index.js')
const bettingStrategies = require('./betting.js')

function simulateHands ({numHands, bettingStrategy, showDetail}) {
function simulateHands ({ numHands, bettingStrategy, showDetail }) {
const summaryTemplate = {
balance: 0,
rollCount: 0,
Expand Down Expand Up @@ -164,7 +164,7 @@ if (require.main === module) {
const showDetail = process.argv[4]
console.log(`Simulating ${numHands} Craps Hand(s)`)
console.log(`Using betting strategy: ${bettingStrategy}`)
const result = simulateHands({numHands, showDetail, bettingStrategy})
const result = simulateHands({ numHands, showDetail, bettingStrategy })
printResults({ ...result, showDetail })
} else {
module.exports = simulateHands
Expand Down