-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfiveCount.js
More file actions
31 lines (22 loc) · 773 Bytes
/
fiveCount.js
File metadata and controls
31 lines (22 loc) · 773 Bytes
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
const POINT_NUMBERS = [4, 5, 6, 8, 9, 10]
function updateFiveCount (count, hand) {
if (!hand.result) return count
if (count === 0) {
return hand.result === 'point set' ? 1 : 0
}
if (count < 4) return count + 1
if (count === 4) {
return POINT_NUMBERS.includes(hand.diceSum) ? 5 : 4
}
return 5
}
function withFiveCount (strategy) {
return function fiveCountStrategy ({ rules, bets, hand, playerMind }) {
playerMind.fiveCount = playerMind.fiveCount || { count: 0 }
const count = updateFiveCount(playerMind.fiveCount.count, hand)
playerMind.fiveCount.count = count
if (count < 5) return Object.assign(bets || {}, { new: 0 })
return strategy({ rules, bets, hand, playerMind })
}
}
export { updateFiveCount, withFiveCount }