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-07-22 12:54:28 -0400
commit337178ee3957eb5c91d1749b589c38517e7e2a25 (patch)
tree0017f727bc316a17281d3160341c01c98cb630d1
parent5bce5ab13f1ff0d787299dc6d302a24edc632482 (diff)
downloadmuhqs-game-337178ee3957eb5c91d1749b589c38517e7e2a25.tar.gz
muhqs-game-337178ee3957eb5c91d1749b589c38517e7e2a25.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
+}