aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-19 18:47:07 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:25 +0200
commitd50265d15d63e01954ea734f989ce02cd4c2f564 (patch)
treed6452ab3ad69a076d62dba30c69ade176f3abd8c /go
parentb40ed097c2c327414b0d6945a231ac3278f00544 (diff)
downloadmuhqs-game-d50265d15d63e01954ea734f989ce02cd4c2f564.tar.gz
muhqs-game-d50265d15d63e01954ea734f989ce02cd4c2f564.zip
allow more flexible player creation
Diffstat (limited to 'go')
-rw-r--r--go/game/player.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/go/game/player.go b/go/game/player.go
index 38e959da..ef88cd81 100644
--- a/go/game/player.go
+++ b/go/game/player.go
@@ -25,12 +25,8 @@ type Player struct {
knownStores map[Position]bool
}
-// Creates a new player
-// It initializes the players starting deck from the map's deck list if available.
-func NewPlayer(id int, name string, deck *Deck, gameState *LocalState, color color.Color) *Player {
- store := NewStore()
- deck.MoveInto(store)
-
+// NewPlayerWithStore creates a new player.
+func NewPlayerWithDeckAndStore(id int, name string, deck *Deck, store *Store, gameState *LocalState) *Player {
p := Player{
Id: id,
Name: name,
@@ -39,24 +35,39 @@ func NewPlayer(id int, name string, deck *Deck, gameState *LocalState, color col
DrawPerTurn: MAX_DRAW,
Hand: NewHand(),
DiscardPile: NewDiscardPile(),
+ Deck: deck,
Store: store,
gameState: gameState,
Ctrl: nil,
knownStores: make(map[Position]bool),
}
+ return &p
+}
+
+// NewPlayer creates a new player moving its deck to the store.
+// It initializes the players starting deck from the map's deck list if available.
+func NewPlayer(id int, name string, deck *Deck, gameState *LocalState) *Player {
+ store := NewStore()
+ deck.MoveInto(store)
+
+ p := NewPlayerWithDeckAndStore(id, name, nil, store, gameState)
+
// Prepopulate the Deck
if gameState != nil {
if m := gameState.Map(); m != nil {
p.Deck = NewDeckFromDeckList(m.StartDeckList)
}
- } else {
+ }
+
+ if p.Deck == nil {
p.Deck = NewDeck()
}
- return &p
+ return p
}
+// NewDraftPlayer returns a player struct only initialized with a name and an empty deck.
func NewDraftPlayer(name string) *Player {
p := Player{
Name: name,