package game import ( "encoding/json" "github.com/google/uuid" ) type Game struct { ID uuid.UUID `json:"id"` Age uint `json:"turn"` // Game's turn number Map Map `json:"map"` Race []Race `json:"races"` } func (g Game) Votes(raceID uuid.UUID) float64 { // XXX: calculate [Race]Population once when loading Game from Storage? var pop float64 for i := range g.Map.Planet { if g.Map.Planet[i].Owner == raceID { pop += g.Map.Planet[i].Population } } return pop / 1000. } func (g Game) MarshalBinary() (data []byte, err error) { return json.Marshal(&g) }