aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-09-02 14:09:24 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-09-03 12:39:41 +0200
commitfcc55c047eaf7275b9154b8448a56800849fccae (patch)
treee777e4c400650c4fa305335531f7863d349e35cb
parentffa627219c0a6bfe133c086d69a730054d69d69f (diff)
downloadmuhqs-game-fcc55c047eaf7275b9154b8448a56800849fccae.tar.gz
muhqs-game-fcc55c047eaf7275b9154b8448a56800849fccae.zip
fix reported stores by the game state
-rw-r--r--go/game/state.go17
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) {