Skip to content

Commit

Permalink
Bug fix: no cards were showing at end of round
Browse files Browse the repository at this point in the history
  • Loading branch information
alexclewontin committed Oct 4, 2020
1 parent 3a355bb commit 1acb7f5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
9 changes: 5 additions & 4 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ func deal(g *Game, pn uint, data uint) error {

g.pots = []Pot{}

for !g.players[g.dealerNum].Ready {
g.dealerNum = (g.dealerNum + 1) % uint(len(g.players))
}

g.updateBlindNums()

g.actionNum = g.utgNum
Expand All @@ -201,7 +197,12 @@ func deal(g *Game, pn uint, data uint) error {
g.players[i].Cards[0] = g.deck.Pop()
g.players[i].Cards[1] = g.deck.Pop()
g.players[i].In = true
} else {
g.players[i].Cards[0] = 0
g.players[i].Cards[1] = 0
}

g.players[i].Called = false
}

g.players[g.sbNum].putInChips(g.config.SmallBlind)
Expand Down
4 changes: 0 additions & 4 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ func (g *Game) canOpen(pn uint) bool {
func (g *Game) resetForNextHand() {

for i := range g.players {
g.players[i].In = false
g.players[i].Called = false
g.players[i].Bet = 0
g.players[i].TotalBet = 0

Expand All @@ -245,8 +243,6 @@ func (g *Game) resetForNextHand() {
g.dealerNum = (g.dealerNum + 1) % uint(len(g.players))
}

g.pots = []Pot{}

g.setStageAndBetting(PreDeal, false)
}

Expand Down
57 changes: 33 additions & 24 deletions views.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type GameView struct {
func (g *Game) copyToView() *GameView {
//TODO: Is there some way to do this programatically? I considered using
// reflection, but since that happens at runtime it is less performant.
// Something like reflection, but evaulated at compile-time would be ideal
// Something like reflection, but evaluated at compile-time would be ideal
// Probably using go generate.

//WARNING: This needs to be the deepest of deep copies. If adding a field,
Expand Down Expand Up @@ -152,31 +152,40 @@ func (g *Game) GeneratePlayerView(pn uint) *GameView {
}

if g.getStage() == PreDeal {

showCards(g.calledNum)
_, scoreToBeat := BestFiveOfSeven(
g.players[g.calledNum].Cards[0],
g.players[g.calledNum].Cards[1],
g.communityCards[0],
g.communityCards[1],
g.communityCards[2],
g.communityCards[3],
g.communityCards[4],
)

for i := range g.players {
pni := (g.calledNum + uint(i)) % uint(len(g.players))
_, iScore := BestFiveOfSeven(
g.players[pni].Cards[0],
g.players[pni].Cards[1],
g.communityCards[0],
g.communityCards[1],
g.communityCards[2],
g.communityCards[3],
g.communityCards[4],
)

if (iScore < scoreToBeat) && g.players[pni].In {
showCards(pni)
scoreToBeat = iScore
}
}

for _, pot := range g.pots {

winnercount := 0
for i := 0; i < len(g.players); i++ {
pni := (g.calledNum + uint(i)) % uint(len(g.players))
for _, j := range pot.WinningPlayerNums {
if pni == j {
winnercount = winnercount + 1
showCards(pni)
break
}
}

if winnercount == len(pot.WinningPlayerNums) {
break
}

if winnercount == 0 {
for _, j := range pot.EligiblePlayerNums {
if pni == j {
showCards(pni)
break
}
}
}
for _, j := range pot.WinningPlayerNums {
showCards(j)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion views_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestGame_GenerateOmniViewChangedVals(t *testing.T) {
panic(err)
}

fmt.Printf("%s", string(jsonView))
t.Logf("%s", string(jsonView))

if !reflect.DeepEqual(g, tt.want) {
t.Errorf("\nBefore: %+v\nAfter %+v", tt.want, g)
Expand Down

0 comments on commit 1acb7f5

Please sign in to comment.