Files
galaxy-game/pkg/model/game/game.go
T
2025-09-26 20:54:34 +03:00

34 lines
678 B
Go

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)
}
func (g Game) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, &g)
}