-
Notifications
You must be signed in to change notification settings - Fork 1
/
settle.js
87 lines (64 loc) · 1.91 KB
/
settle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function passLine ({ bets, hand, rules }) {
if (!bets?.pass?.line) return { bets }
const actionResults = ['seven out', 'point win', 'comeout win', 'comeout loss']
const betHasAction = actionResults.includes(hand.result)
if (!betHasAction) return { bets } // keep bets intact if no action
const payout = {
type: hand.result,
principal: bets.pass.line.amount,
profit: bets.pass.line.amount * 1
}
delete bets.pass.line // clear pass line bet on action
if (hand.result === 'comeout loss' || hand.result === 'seven out') return { bets }
return { payout, bets }
}
function passOdds ({ bets, hand, rules }) {
if (!bets?.pass?.odds) return { bets }
const actionResults = ['seven out', 'point win']
const betHasAction = actionResults.includes(hand.result)
if (!betHasAction) return { bets } // keep bets intact if no action
const payouts = {
4: 2,
5: 3 / 2,
6: 6 / 5,
8: 6 / 5,
9: 3 / 2,
10: 2
}
const payout = {
type: 'pass odds win',
principal: bets.pass.odds.amount,
profit: bets.pass.odds.amount * payouts[hand.diceSum]
}
delete bets.pass.odds // clear pass odds bet on action
if (hand.result === 'seven out') return { bets }
return { payout, bets }
}
function all ({ bets, hand, rules }) {
const payouts = []
const passLineResult = passLine({ bets, hand, rules })
bets = passLineResult.bets
payouts.push(passLineResult.payout)
const passOddsResult = passOdds({ bets, hand, rules })
bets = passOddsResult.bets
payouts.push(passOddsResult.payout)
bets.payouts = payouts.reduce((memo, payout) => {
if (!payout) return memo
memo.principal += payout.principal
memo.profit += payout.profit
memo.total += payout.principal + payout.profit
memo.ledger.push(payout)
return memo
}, {
principal: 0,
profit: 0,
total: 0,
ledger: []
})
return bets
}
module.exports = {
passLine,
passOdds,
all
}