diff --git a/betting.js b/betting.js index ec70a45..c6ca88c 100644 --- a/betting.js +++ b/betting.js @@ -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) @@ -108,8 +147,10 @@ function minPassLineMaxOddsPlaceSixEight (opts) { module.exports = { minPassLineOnly, + lineMaxOdds, minPassLineMaxOdds, placeSixEight, + placeSixEightUnlessPoint, minPassLinePlaceSixEight, minPassLineMaxOddsPlaceSixEight } diff --git a/betting.test.js b/betting.test.js index e9fd9cf..0a058fa 100644 --- a/betting.test.js +++ b/betting.test.js @@ -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, diff --git a/hands.js b/hands.js index e9ef0e7..85c5f9e 100644 --- a/hands.js +++ b/hands.js @@ -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, @@ -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