diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-09-02 14:09:24 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-09-03 12:39:41 +0200 |
| commit | fcc55c047eaf7275b9154b8448a56800849fccae (patch) | |
| tree | e777e4c400650c4fa305335531f7863d349e35cb /go | |
| parent | ffa627219c0a6bfe133c086d69a730054d69d69f (diff) | |
| download | muhqs-game-fcc55c047eaf7275b9154b8448a56800849fccae.tar.gz muhqs-game-fcc55c047eaf7275b9154b8448a56800849fccae.zip | |
fix reported stores by the game state
Diffstat (limited to 'go')
| -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) { |
