@@ -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,
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user