Skip to content

Commit badf36d

Browse files
authored
Merge pull request #29 from tphummel/ai/factor-out-pass-line-and-odds-betting-strategy
2 parents e51e06c + 6480dd5 commit badf36d

File tree

2 files changed

+115
-13
lines changed

2 files changed

+115
-13
lines changed

betting.js

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,65 @@ function minPassLineOnly (opts) {
2222
return bets
2323
}
2424

25-
function minPassLineMaxOdds (opts) {
26-
const bets = minPassLineOnly(opts)
27-
const { rules, hand } = opts
28-
const makeNewPassOddsBet = hand.isComeOut === false && !bets?.pass?.odds
29-
if (process.env.DEBUG) console.log(`[decision] make a new pass odds bet?: ${makeNewPassOddsBet}`)
30-
31-
if (makeNewPassOddsBet) {
32-
const oddsAmount = rules.maxOddsMultiple[hand.point] * bets.pass.line.amount
33-
if (process.env.DEBUG) console.log(`[action] make pass odds bet $${oddsAmount}`)
34-
bets.pass.odds = {
35-
amount: oddsAmount
25+
function lineMaxOdds ({
26+
rules,
27+
bets: existingBets,
28+
point,
29+
shouldMakeLineBet,
30+
shouldMakeOddsBet,
31+
betKey = 'pass'
32+
}) {
33+
const bets = Object.assign({ new: 0 }, existingBets)
34+
35+
bets[betKey] = bets[betKey] || {}
36+
37+
const makeLineBet = shouldMakeLineBet && !bets[betKey].line
38+
if (process.env.DEBUG) {
39+
console.log(`[decision] make a new ${betKey} line bet?: ${makeLineBet}`)
40+
}
41+
42+
if (makeLineBet) {
43+
const newLineBet = { amount: rules.minBet }
44+
bets[betKey].line = newLineBet
45+
bets.new += newLineBet.amount
46+
if (process.env.DEBUG) {
47+
console.log(`[action] make ${betKey} line bet $${newLineBet.amount}`)
3648
}
49+
} else if (process.env.DEBUG) {
50+
console.log(`[action] ${betKey} line bet unchanged`)
51+
}
52+
53+
const makeOddsBet = shouldMakeOddsBet && bets[betKey].line && !bets[betKey].odds
54+
if (process.env.DEBUG) {
55+
console.log(`[decision] make a new ${betKey} odds bet?: ${makeOddsBet}`)
56+
}
57+
58+
if (makeOddsBet) {
59+
const oddsAmount = rules.maxOddsMultiple[point] * bets[betKey].line.amount
60+
bets[betKey].odds = { amount: oddsAmount }
3761
bets.new += oddsAmount
38-
} else {
39-
if (process.env.DEBUG) console.log('[decision] skip new pass odds bet')
62+
if (process.env.DEBUG) {
63+
console.log(`[action] make ${betKey} odds bet $${oddsAmount}`)
64+
}
65+
} else if (process.env.DEBUG) {
66+
console.log(`[decision] skip new ${betKey} odds bet`)
4067
}
4168

4269
return bets
4370
}
4471

72+
function minPassLineMaxOdds (opts) {
73+
const { rules, hand } = opts
74+
return lineMaxOdds({
75+
rules,
76+
bets: opts.bets,
77+
point: hand.point,
78+
shouldMakeLineBet: hand.isComeOut,
79+
shouldMakeOddsBet: hand.isComeOut === false,
80+
betKey: 'pass'
81+
})
82+
}
83+
4584
function placeSixEight (opts) {
4685
const { rules, bets: existingBets = {}, hand } = opts
4786
const bets = Object.assign({ new: 0 }, existingBets)
@@ -108,6 +147,7 @@ function minPassLineMaxOddsPlaceSixEight (opts) {
108147

109148
module.exports = {
110149
minPassLineOnly,
150+
lineMaxOdds,
111151
minPassLineMaxOdds,
112152
placeSixEight,
113153
placeSixEightUnlessPoint,

betting.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,68 @@ tap.test('minPassLineOnly: bet exists, point set', (t) => {
9696
t.end()
9797
})
9898

99+
tap.test('lineMaxOdds: new line bet only', (t) => {
100+
const rules = {
101+
minBet: 5,
102+
maxOddsMultiple: {
103+
4: 3,
104+
5: 4,
105+
6: 5,
106+
8: 5,
107+
9: 4,
108+
10: 3
109+
}
110+
}
111+
112+
const hand = { isComeOut: true }
113+
114+
const updatedBets = lib.lineMaxOdds({
115+
rules,
116+
hand,
117+
shouldMakeLineBet: true,
118+
shouldMakeOddsBet: false,
119+
point: 4,
120+
betKey: 'pass'
121+
})
122+
123+
t.equal(updatedBets.pass.line.amount, rules.minBet)
124+
t.equal(updatedBets.new, rules.minBet)
125+
126+
t.end()
127+
})
128+
129+
tap.test('lineMaxOdds: add odds to existing line bet', (t) => {
130+
const rules = {
131+
minBet: 5,
132+
maxOddsMultiple: {
133+
4: 3,
134+
5: 4,
135+
6: 5,
136+
8: 5,
137+
9: 4,
138+
10: 3
139+
}
140+
}
141+
142+
const hand = { isComeOut: false, point: 6 }
143+
const bets = { pass: { line: { amount: rules.minBet } } }
144+
145+
const updatedBets = lib.lineMaxOdds({
146+
rules,
147+
hand,
148+
bets,
149+
shouldMakeLineBet: false,
150+
shouldMakeOddsBet: true,
151+
point: hand.point,
152+
betKey: 'pass'
153+
})
154+
155+
t.equal(updatedBets.pass.odds.amount, rules.maxOddsMultiple['6'] * rules.minBet)
156+
t.equal(updatedBets.new, updatedBets.pass.odds.amount)
157+
158+
t.end()
159+
})
160+
99161
tap.test('minPassLineMaxOdds: make new bet upon establishing point', (t) => {
100162
const rules = {
101163
minBet: 5,

0 commit comments

Comments
 (0)