From c7ee3760bac1c9c0b75244e9152c1ce308f79240 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sat, 3 Feb 2024 22:34:29 -0600 Subject: [PATCH] implement player loses on move timer expires Fixes #11. --- game.go | 5 ++++- game/game.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/game.go b/game.go index 319bfe8..0e93038 100644 --- a/game.go +++ b/game.go @@ -72,6 +72,7 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <- dl := time.Now().Add(timeLimit) broadcast(ctx, g, dealer, chall, obs, dl) tick := time.NewTicker(timeLimit) + defer tick.Stop() for { select { case <-ctx.Done(): @@ -120,7 +121,9 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <- tick.Reset(timeLimit) case <-tick.C: slog.InfoContext(ctx, "out of time") - // TODO(zeph): current player concedes + g.Expire() + gameOver(ctx, dealer, chall, obs) + return } // Clear observers who have left. for k := len(obs) - 1; k >= 0; k-- { diff --git a/game/game.go b/game/game.go index 898e282..62efcab 100644 --- a/game/game.go +++ b/game/game.go @@ -240,6 +240,11 @@ func (g *Match) Concede(id player.ID) error { return ErrRoundEnded } +// Expire makes the current player concede. +func (g *Match) Expire() { + g.Concede(g.CurrentPlayer().id) +} + // DTO returns the current match state as viewed by the given player and with // the given deadline on the current player's next move. func (g *Match) DTO(id player.ID, deadline time.Time) serve.Game {