use game errors in game actor

This commit is contained in:
Branden J Brown 2024-01-31 07:36:31 -06:00
parent 09521cb5b0
commit 245109883a
1 changed files with 6 additions and 10 deletions

16
game.go
View File

@ -24,13 +24,7 @@ func applyAction(g *game.Match, a action) error {
case "quit":
return g.Concede(a.Player)
case "across", "self":
if err := g.Shoot(a.Player, a.Action == "self"); err != nil {
return err
}
if g.RoundWinner() != nil {
return errRoundEnded
}
return nil
return g.Shoot(a.Player, a.Action == "self")
case "0":
return g.Apply(a.Player, 0)
case "1":
@ -88,7 +82,7 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <-
switch err {
case nil:
broadcast(ctx, g, dealer, chall, obs)
case errRoundEnded:
case game.ErrRoundEnded:
broadcast(ctx, g, dealer, chall, obs)
if g.MatchWinner() != nil {
gameOver(ctx, dealer, chall, obs)
@ -97,7 +91,10 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <-
}
g.NextRound()
broadcast(ctx, g, dealer, chall, obs)
// TODO(zeph): broadcast shell counts?
case game.ErrGameEnded:
broadcast(ctx, g, dealer, chall, obs)
g.NextGame()
broadcast(ctx, g, dealer, chall, obs)
case game.ErrWrongTurn: // do nothing
case errWeirdAction:
slog.WarnContext(ctx, "nonsense action", "from", a.Player, "action", a.Action)
@ -159,7 +156,6 @@ func gameOver(ctx context.Context, dealer, chall person, obs []person) {
}
var (
errRoundEnded = errors.New("someone h*ckin died")
errWeirdAction = errors.New("unknown action")
errMatchExpired = errors.New("there is a time limit on matches please")
)