From fcc55c047eaf7275b9154b8448a56800849fccae Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 2 Sep 2025 14:09:24 +0200 Subject: fix reported stores by the game state --- go/game/state.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'go') diff --git a/go/game/state.go b/go/game/state.go index 76133498..9a76a945 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -3,13 +3,13 @@ package game import ( "errors" "fmt" + "maps" "math/rand" + "slices" "strconv" "strings" "time" - "golang.org/x/exp/slices" - "muhq.space/muhqs-game/go/log" ) @@ -32,7 +32,6 @@ type State interface { } type LocalState struct { - stores []*Store exile *PileOfCardsBase _map *Map stack *Stack @@ -79,8 +78,18 @@ func (s *LocalState) Map() *Map { return s._map } +// Stores returns a slice of Stores. +// Either all stores on the map or the stores of all players are returned. func (s *LocalState) Stores() []*Store { - return s.stores + if s._map.HasStores() { + return slices.Collect(maps.Values(s._map.Stores)) + } + + stores := make([]*Store, 0, len(s.players)) + for _, p := range s.players { + stores = append(stores, p.Store) + } + return stores } func (s *LocalState) SetMap(m *Map) { -- cgit v1.2.3