aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-19 18:48:01 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:25 +0200
commitde2a126a47e6c83775389035371c008396730391 (patch)
treee1a6b634e0009dfd1f23acb4a252740618f89cbb
parentd50265d15d63e01954ea734f989ce02cd4c2f564 (diff)
downloadmuhqs-game-de2a126a47e6c83775389035371c008396730391.tar.gz
muhqs-game-de2a126a47e6c83775389035371c008396730391.zip
modernize and add new random deck function
-rw-r--r--go/game/deck.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/go/game/deck.go b/go/game/deck.go
index 1f9539a9..ea69fcc7 100644
--- a/go/game/deck.go
+++ b/go/game/deck.go
@@ -63,8 +63,8 @@ func NewDeckFromDeckList(deckList string) *Deck {
// trim last trailing newline
deckList = strings.Trim(deckList, "\n")
- lines := strings.Split(deckList, "\n")
- for _, line := range lines {
+ lines := strings.SplitSeq(deckList, "\n")
+ for line := range lines {
tokens := strings.SplitN(line, " ", 2)
cardPath := tokens[1]
amount, err := strconv.Atoi(tokens[0])
@@ -72,10 +72,22 @@ func NewDeckFromDeckList(deckList string) *Deck {
log.Fatal(err)
}
- for i := 0; i < amount; i++ {
+ for range amount {
cardPaths = append(cardPaths, cardPath)
}
}
return NewDeckFromCardPaths(cardPaths)
}
+
+func NewRandomDeck(n int, sets []SetIdentifier) *Deck {
+ deck := NewDeck()
+ pool := NewDeck()
+ for _, set := range sets {
+ NewDeckFromCardPaths(set.CardPaths()).MoveInto(pool)
+ }
+
+ cards := NewRandomPackFromPool(pool, n)
+ cards.MoveInto(deck)
+ return deck
+}