deck func consistency

This commit is contained in:
stryan 2021-11-19 13:53:19 -05:00
parent 354167535a
commit 8d4e875891

30
deck.go
View File

@ -2,6 +2,7 @@ package tome_lib
import ( import (
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"time" "time"
) )
@ -31,22 +32,31 @@ func (d *Deck) Shuffle() {
} }
} }
func (d *Deck) Scry(s int) []*Card { func (d *Deck) Scry(s int) *Deck {
seen := []*Card{} seen := make([]*Card, s)
if len(d.Cards) < s { if len(d.Cards) < s {
seen = d.Cards copy(seen, d.Cards)
d.Cards = []*Card{} d.Reset()
return seen } else {
scrybox := d.Cards[(len(d.Cards) - s):len(d.Cards)]
res := copy(seen, scrybox)
if res == 0 {
panic("Error copy scrybox")
}
log.Println(seen)
d.Cards = d.Cards[0 : len(d.Cards)-s]
} }
seen = d.Cards[(len(d.Cards) - s):len(d.Cards)] return DeckFromCards(seen)
d.Cards = d.Cards[0 : len(d.Cards)-s]
return seen
} }
func (d *Deck) Bottom(result []*Card) { func (d *Deck) Bottom(bot *Deck) {
d.Cards = append(result, d.Cards...) //Should shuffle result first? d.Cards = append(bot.Cards, d.Cards...) //Should shuffle result first?
} }
func (d *Deck) Size() int { func (d *Deck) Size() int {
return len(d.Cards) return len(d.Cards)
} }
func (d *Deck) Reset() {
d.Cards = []*Card{}
}