dkforest

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

commit 6054bc82d2d11ae873e3b3dd37c1eb073b1e83a9
parent 4f73cd833637b37c80ac0a4df46f5db8abe70a92
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  5 Dec 2023 16:46:12 -0500

end game when everyone folded

Diffstat:
Mpkg/web/handlers/poker.go | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 53 insertions(+), 7 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -141,9 +141,17 @@ func (g *PokerGame) Deal(roomID string) { g.Ongoing = &Ongoing{Deck: deck, Players: players, WaitTurnEvent: PokerWaitTurnEvent{Idx: -1}} go func() { - waitPlayersActionFn := func() { + waitPlayersActionFn := func() bool { lastRisePlayerIdx := -1 minBet := 0 + + playerAlive := 0 + for _, p := range g.Ongoing.Players { + if p != nil && !p.Folded { + playerAlive++ + } + } + OUTER: for { for i, p := range g.Ongoing.Players { @@ -175,6 +183,10 @@ func (g *PokerGame) Deal(roomID string) { if p.Bet < minBet { player.Folded = true PokerPubSub.Pub(roomTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx}) + playerAlive-- + if playerAlive == 1 { + break OUTER + } } break LOOP } @@ -185,6 +197,10 @@ func (g *PokerGame) Deal(roomID string) { if evt.Fold { player.Folded = true PokerPubSub.Pub(roomTopic, PlayerFoldEvent{Card1Idx: player.Cards[0].Idx, Card2Idx: player.Cards[1].Idx}) + playerAlive-- + if playerAlive == 1 { + break OUTER + } } else if evt.Check { if g.Ongoing.Players[i].Bet < minBet { fmt.Println("NEED TO BET", minBet-g.Ongoing.Players[i].Bet) @@ -256,6 +272,8 @@ func (g *PokerGame) Deal(roomID string) { evt := PokerWaitTurnEvent{Idx: -1, MainPot: g.Ongoing.MainPot} PokerPubSub.Pub(roomTopic, evt) g.Ongoing.WaitTurnEvent = evt + + return playerAlive == 1 } type Seat struct { @@ -340,7 +358,9 @@ func (g *PokerGame) Deal(roomID string) { // Wait for players to bet/call/check/fold... time.Sleep(time.Second) - waitPlayersActionFn() + if waitPlayersActionFn() { + goto END + } // Burn time.Sleep(time.Second) @@ -354,7 +374,9 @@ func (g *PokerGame) Deal(roomID string) { // Wait for players to bet/call/check/fold... time.Sleep(time.Second) - waitPlayersActionFn() + if waitPlayersActionFn() { + goto END + } // Burn time.Sleep(time.Second) @@ -366,7 +388,9 @@ func (g *PokerGame) Deal(roomID string) { // Wait for players to bet/call/check/fold... time.Sleep(time.Second) - waitPlayersActionFn() + if waitPlayersActionFn() { + goto END + } // Burn time.Sleep(time.Second) @@ -378,7 +402,24 @@ func (g *PokerGame) Deal(roomID string) { // Wait for players to bet/call/check/fold... time.Sleep(time.Second) - waitPlayersActionFn() + if waitPlayersActionFn() { + goto END + } + + // TODO: Show cards + + END: + + // TODO: evaluate hands, and crown winner + var winner *PokerPlayer + for _, p := range g.Ongoing.Players { + if p != nil { + winner = p + break + } + } + winner.Cash += g.Ongoing.MainPot + g.Ongoing.MainPot = 0 for idx := range g.Players { if g.Ongoing.Players[idx] != nil { @@ -386,7 +427,6 @@ func (g *PokerGame) Deal(roomID string) { } } - // TODO: evaluate hands, and crown winner g.IsGameDone = true PokerPubSub.Pub(roomTopic, GameIsDoneEvent{DeckStr: strings.Join(g.Ongoing.Deck, "")}) @@ -971,7 +1011,13 @@ Loop: continue } else if evt, ok := payload.(GameIsDoneEvent); ok { - send(`<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>`) + html := `<style>#deckStr:before { content: "` + evt.DeckStr + `"; }</style>` + for i, p := range g.Players { + if p.Username != "" { + html += `<style>#seat` + strconv.Itoa(i+1) + `_cash:before { content: "` + strconv.Itoa(p.Cash) + `"; }</style>` + } + } + send(html) c.Response().Flush() continue