parent
a38bf9631f
commit
c7ee3760ba
5
game.go
5
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-- {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user