diff options
| -rw-r--r-- | go/game/state.go | 17 |
1 files changed, 13 insertions, 4 deletions
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) { |
