dkforest

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

commit 0f4949bd06f819e056c95043e2eca6a257b2639a
parent 0cd9aed1fbde986148569587e86705704e501e3f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 18 Dec 2023 21:39:53 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 74++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 38 insertions(+), 36 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -931,6 +931,38 @@ var dealerTokenPos = [][]int{ {363, 123}, } +func burnCard(g *PokerGame, idx, burnIdx *int) { + ongoing := g.Ongoing + *idx++ + evt := PokerEvent{ + ID: "card" + itoa(*idx), + Name: "", + Idx: *idx, + Top: BurnStackY + (*burnIdx * 2), + Left: BurnStackX + (*burnIdx * 4), + } + PokerPubSub.Pub(g.RoomID.Topic(), evt) + ongoing.AddEvent(evt) + *burnIdx++ +} + +func dealCard(g *PokerGame, idx *int, dealCardIdx int) { + ongoing := g.Ongoing + card := ongoing.Deck[*idx] + *idx++ + evt := PokerEvent{ + ID: "card" + itoa(*idx), + Name: card, + Idx: *idx, + Top: DealY, + Left: DealX + (dealCardIdx * DealSpacing), + Reveal: true, + } + PokerPubSub.Pub(g.RoomID.Topic(), evt) + ongoing.AddEvent(evt) + ongoing.communityCards = append(ongoing.communityCards, card) +} + func dealPlayersCards(g *PokerGame, seats []Seat, idx *int) { roomID := g.RoomID ongoing := g.Ongoing @@ -1012,37 +1044,7 @@ func dealerThread(g *PokerGame) { } idx := 0 - burnIdx := 0 - burnCard := func() { - idx++ - evt := PokerEvent{ - ID: "card" + itoa(idx), - Name: "", - Idx: idx, - Top: BurnStackY + (burnIdx * 2), - Left: BurnStackX + (burnIdx * 4), - } - PokerPubSub.Pub(roomTopic, evt) - ongoing.AddEvent(evt) - burnIdx++ - } - - dealCard := func(dealCardIdx int) { - card := ongoing.Deck[idx] - idx++ - evt := PokerEvent{ - ID: "card" + itoa(idx), - Name: card, - Idx: idx, - Top: DealY, - Left: DealX + (dealCardIdx * DealSpacing), - Reveal: true, - } - PokerPubSub.Pub(roomTopic, evt) - ongoing.AddEvent(evt) - ongoing.communityCards = append(ongoing.communityCards, card) - } sbIdx, bbIdx := g.incrDealerIdx() @@ -1067,10 +1069,10 @@ func dealerThread(g *PokerGame) { // Flop (3 first cards) time.Sleep(time.Second) - burnCard() + burnCard(g, &idx, &burnIdx) for i := 1; i <= 3; i++ { time.Sleep(time.Second) - dealCard(i) + dealCard(g, &idx, i) } // No flop, no drop @@ -1088,9 +1090,9 @@ func dealerThread(g *PokerGame) { // Turn (4th card) time.Sleep(time.Second) - burnCard() + burnCard(g, &idx, &burnIdx) time.Sleep(time.Second) - dealCard(4) + dealCard(g, &idx, 4) // Wait for players to bet/call/check/fold... time.Sleep(time.Second) @@ -1100,9 +1102,9 @@ func dealerThread(g *PokerGame) { // River (5th card) time.Sleep(time.Second) - burnCard() + burnCard(g, &idx, &burnIdx) time.Sleep(time.Second) - dealCard(5) + dealCard(g, &idx, 5) // Wait for players to bet/call/check/fold... time.Sleep(time.Second)