commit 367c978828ed044e90af75a17366e60e95b6aebf
parent 8f3d16bbd7ca40ded80abcdd32d28866ba42120e
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 16 Dec 2023 05:47:01 -0500
add auto action bet
Diffstat:
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -490,6 +490,7 @@ const (
FoldAction
CallAction
CheckAction
+ BetAction
)
const (
@@ -499,6 +500,11 @@ const (
breakGetPlayerEventLoop
)
+type AutoAction struct {
+ v int
+ evt PlayerEvent
+}
+
// Return either or not the game ended because only 1 player left playing (or none)
func waitPlayersActionFn(db *database.DkfDB, g *PokerGame, roomID RoomID, skip int, minBet database.PokerChip) bool {
roomTopic := roomID.Topic()
@@ -507,7 +513,7 @@ func waitPlayersActionFn(db *database.DkfDB, g *PokerGame, roomID RoomID, skip i
playerToPlayIdx := (dealerIdx + skip) % len(g.Ongoing.Players)
lastRaisePlayerIdx := -1
newlyAllInPlayers := make([]*PokerPlayer, 0)
- autoCache := make(map[database.Username]int)
+ autoCache := make(map[database.Username]AutoAction)
foldPlayer := func(p *PokerPlayer) {
p.Folded.Store(true)
@@ -666,22 +672,25 @@ RoundIsSettledLoop:
handleAutoActionReceived := func(evt PlayerEvent) int {
roomUserTopic := roomID.UserTopic(evt.Player)
autoAction := autoCache[evt.Player]
- if evt.Fold && autoAction == FoldAction ||
- evt.Call && autoAction == CallAction ||
- evt.Check && autoAction == CheckAction {
+ if evt.Fold && autoAction.v == FoldAction ||
+ evt.Call && autoAction.v == CallAction ||
+ evt.Check && autoAction.v == CheckAction {
delete(autoCache, evt.Player)
PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: ""})
return continueGetPlayerEventLoop
}
if evt.Fold {
- autoCache[evt.Player] = FoldAction
+ autoCache[evt.Player] = AutoAction{v: FoldAction, evt: evt}
PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto fold"})
} else if evt.Call {
- autoCache[evt.Player] = CallAction
+ autoCache[evt.Player] = AutoAction{v: CallAction, evt: evt}
PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto call"})
} else if evt.Check {
- autoCache[evt.Player] = CheckAction
+ autoCache[evt.Player] = AutoAction{v: CheckAction, evt: evt}
PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto check"})
+ } else if evt.Bet > 0 {
+ autoCache[evt.Player] = AutoAction{v: BetAction, evt: evt}
+ PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: "Will auto bet " + evt.Bet.String()})
}
return continueGetPlayerEventLoop
}
@@ -704,11 +713,11 @@ RoundIsSettledLoop:
return actionResult
}
- applyAutoAction := func(autoAction int) (actionResult int) {
- if autoAction > NoAction {
+ applyAutoAction := func(autoAction AutoAction) (actionResult int) {
+ if autoAction.v > NoAction {
time.Sleep(500 * time.Millisecond)
p.LastActionTS = time.Now()
- switch autoAction {
+ switch autoAction.v {
case NoAction:
case FoldAction:
actionResult = doFold()
@@ -716,9 +725,12 @@ RoundIsSettledLoop:
actionResult = doCheck()
case CallAction:
actionResult = doCall()
+ case BetAction:
+ actionResult = doBet(autoAction.evt)
}
}
delete(autoCache, pUsername)
+ PokerPubSub.Pub(roomUserTopic, AutoActionEvent{Message: ""})
return
}