commit 56e50f4f6f1566f9c949b2b936131243c144687d
parent 95636c611f6dda05bf80c17b4c17990f2dc844c3
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 18 Dec 2023 14:42:39 -0500
cleanup
Diffstat:
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -88,7 +88,7 @@ type PlayerEvent struct {
Bet database.PokerChip
}
-func (e PlayerEvent) getAction() int {
+func (e PlayerEvent) getAction() PlayerAction {
action := NoAction
if e.Fold {
action = FoldAction
@@ -533,8 +533,10 @@ func setAutoAction(g *PokerGame, roomUserTopic, msg string) {
g.Ongoing.AutoActionEvent.With(func(v *AutoActionEvent) { *v = evt })
}
+type PlayerAction int
+
const (
- NoAction = iota
+ NoAction PlayerAction = iota
FoldAction
CallAction
CheckAction
@@ -542,6 +544,22 @@ const (
AllInAction
)
+func (a PlayerAction) String() string {
+ switch a {
+ case FoldAction:
+ return "fold"
+ case CallAction:
+ return "call"
+ case CheckAction:
+ return "check"
+ case BetAction:
+ return "bet"
+ case AllInAction:
+ return "all-in"
+ }
+ return ""
+}
+
const (
doNothing = iota
breakRoundIsSettledLoop
@@ -550,7 +568,7 @@ const (
)
type AutoAction struct {
- v int
+ v PlayerAction
evt PlayerEvent
}
@@ -737,21 +755,9 @@ RoundIsSettledLoop:
}
action := evt.getAction()
- msg := ""
- if evt.Fold {
- msg = "Will auto fold"
- } else if evt.Call {
- msg = "Will auto call"
- } else if evt.Check {
- msg = "Will auto check"
- } else if evt.Bet > 0 {
- msg = "Will auto bet"
- } else if evt.AllIn {
- msg = "Will auto all-in"
- }
if action != NoAction {
autoCache[evt.Player] = AutoAction{v: action, evt: evt}
- setAutoAction(g, roomUserTopic, msg)
+ setAutoAction(g, roomUserTopic, "Will auto "+action.String())
}
return continueGetPlayerEventLoop
}