implement player loses on move timer expires

Fixes #11.
This commit is contained in:
Branden J Brown 2024-02-03 22:34:29 -06:00
parent a38bf9631f
commit c7ee3760ba
2 changed files with 9 additions and 1 deletions

View File

@ -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-- {

View File

@ -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 {