aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
+}