Skip to content

Commit

Permalink
Add Leave action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexclewontin committed Dec 3, 2020
1 parent ec61968 commit 053a79e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,31 @@ func fold(g *Game, pn uint, data uint) error {

}

// Leave marks a player as having left the game. This is essentially the same as marking a player
// "not ready" (see ToggleReady) except it also marks the player as "left", which provides a distinct
// state (e.g. so that frontends can render "left" players and "not ready" players differently)
func Leave(g *Game, pn uint, data uint) error {
g.mtx.Lock()
defer g.mtx.Unlock()
return toggleReady(g, pn, data)
}

func leave(g *Game, pn uint, data uint) error {
p := g.getPlayer(pn)
var err error

if p.Ready {
err = toggleReady(g, pn, data)
if err != nil {
return err
}
}

p.Left = true

return nil
}

// ToggleReady marks a player as "ready" if they are currently "not ready"
// or "not ready" if they are currently "ready." If the player attempting it is in the current round
// ToggleReady will return an error. If the player attempting it has no money, ToggleReady will return an error.
Expand Down Expand Up @@ -319,5 +344,7 @@ func toggleReady(g *Game, pn uint, data uint) error {
g.updateBlindNums()
}

p.Left = false

return nil
}
1 change: 1 addition & 0 deletions player.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type player struct {
Ready bool
In bool
Called bool
Left bool
TotalBuyIn uint
Stack uint
Bet uint
Expand Down

0 comments on commit 053a79e

Please sign in to comment.