skeleton move timer

For #11.
This commit is contained in:
2024-02-03 21:11:09 -06:00
parent ae1cf18d6d
commit 566de4066b
4 changed files with 37 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ package game
import (
"errors"
"time"
"git.sunturtle.xyz/studio/shotgun/player"
"git.sunturtle.xyz/studio/shotgun/serve"
@@ -239,8 +240,9 @@ func (g *Match) Concede(id player.ID) error {
return ErrRoundEnded
}
// DTO returns the current match state as viewed by the given player.
func (g *Match) DTO(id player.ID) serve.Game {
// 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 {
var live, blank int
if g.action.gameStart() {
live = len(g.shells) / 2
@@ -265,6 +267,7 @@ func (g *Match) DTO(id player.ID) serve.Game {
Damage: g.damage,
Shell: g.Peek(id),
Previous: g.prev,
Deadline: time.Now().UnixMilli(),
Live: live,
Blank: blank,
}

View File

@@ -2,6 +2,7 @@ package game
import (
"testing"
"time"
"github.com/google/uuid"
@@ -455,13 +456,13 @@ func TestGameDTO(t *testing.T) {
Live: len(g.shells) / 2,
Blank: (len(g.shells) + 1) / 2,
}
if got := g.DTO(dealer); want != got {
if got := g.DTO(dealer, time.UnixMilli(0)); want != got {
t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
}
if got := g.DTO(chall); want != got {
if got := g.DTO(chall, time.UnixMilli(0)); want != got {
t.Errorf("challenger sees the wrong thing:\nwant %+v\ngot %+v", want, got)
}
if got := g.DTO(player.ID{}); want != got {
if got := g.DTO(player.ID{}, time.UnixMilli(0)); want != got {
t.Errorf("observer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
}
}
@@ -481,13 +482,13 @@ func TestGameDTO(t *testing.T) {
Live: 0,
Blank: 0,
}
if got := g.DTO(dealer); want != got {
if got := g.DTO(dealer, time.UnixMilli(0)); want != got {
t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
}
if got := g.DTO(chall); want != got {
if got := g.DTO(chall, time.UnixMilli(0)); want != got {
t.Errorf("challenger sees the wrong thing:\nwant %+v\ngot %+v", want, got)
}
if got := g.DTO(player.ID{}); want != got {
if got := g.DTO(player.ID{}, time.UnixMilli(0)); want != got {
t.Errorf("observer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
}
}