45 lines
752 B
Go
45 lines
752 B
Go
|
package main
|
||
|
|
||
|
import "math/rand"
|
||
|
|
||
|
type Deck struct {
|
||
|
Cards []Card
|
||
|
}
|
||
|
|
||
|
func NewDeck() *Deck {
|
||
|
cards := []Card{Valk}
|
||
|
for i := 0; i < 3; i++ {
|
||
|
for j := 1; j < 14; j++ {
|
||
|
cards = append(cards, Card(j))
|
||
|
}
|
||
|
}
|
||
|
return &Deck{
|
||
|
Cards: cards,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (d *Deck) Shuffle() {
|
||
|
cards := d.Cards
|
||
|
for i := range cards {
|
||
|
j := rand.Intn(i + 1)
|
||
|
cards[i], cards[j] = cards[j], cards[i]
|
||
|
}
|
||
|
d.Cards = cards
|
||
|
}
|
||
|
|
||
|
func (d *Deck) Scry(s int) []Card {
|
||
|
seen := []Card{}
|
||
|
if len(d.Cards) < s {
|
||
|
seen = d.Cards
|
||
|
d.Cards = []Card{}
|
||
|
return seen
|
||
|
}
|
||
|
seen = d.Cards[(len(d.Cards) - s):len(d.Cards)]
|
||
|
d.Cards = d.Cards[0 : len(d.Cards)-s]
|
||
|
return seen
|
||
|
}
|
||
|
|
||
|
func (d *Deck) Bottom(result []Card) {
|
||
|
d.Cards = append(result, d.Cards...) //Should shuffle result first?
|
||
|
}
|