dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit e607d77d0b1639fee37332156eb621104ea2960c
parent 8ab28bb6e44a259e0cc6bbf5c34af10f1a230db8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  5 Dec 2023 17:56:30 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker.go | 47+++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -104,6 +104,30 @@ func (g *Ongoing) GetPlayer(player string) *PokerPlayer { return nil } +func isRoundSettled(players []*PokerPlayer) bool { + allSettled := true + b := -1 + for _, p := range players { + if p != nil { + if p.Folded { + continue + } + if p.Cash == 0 { // all in + continue + } + if b == -1 { + b = p.Bet + } else { + if p.Bet != b { + allSettled = false + break + } + } + } + } + return allSettled +} + func (g *PokerGame) Deal(roomID string) { roomTopic := "room_" + roomID @@ -239,28 +263,7 @@ func (g *PokerGame) Deal(roomID string) { } // All settle when all players have the same bet amount - allSettled := true - b := -1 - for _, p := range g.Ongoing.Players { - if p != nil { - if p.Folded { - continue - } - if p.Cash == 0 { // all in - continue - } - if b == -1 { - b = p.Bet - } else { - if p.Bet != b { - allSettled = false - break - } - } - } - } - - if allSettled { + if isRoundSettled(g.Ongoing.Players) { break } }