diff --git a/cube.go b/cube.go deleted file mode 100644 index f2b9936..0000000 --- a/cube.go +++ /dev/null @@ -1,5 +0,0 @@ -package draft - -type Cube struct { - Cards []Card -} diff --git a/mlp/booster.go b/mlp/booster.go index ef7578e..020a5b8 100644 --- a/mlp/booster.go +++ b/mlp/booster.go @@ -29,8 +29,8 @@ on set. Specifically, this is the RR ratio for each set: */ -// BoxSchema returns the pack schema from a booster box for a specific set -func (set *Set) BoxSchema() draft.PackSchema { +// PackSchema returns the pack schema from a booster box for a specific set +func (set *Set) PackSchema() draft.PackSchema { // Return blank schemas for invalid sets if set.ID == SetRockNRave || set.ID == SetCelestialSolstice { return draft.PackSchema{} diff --git a/mlp/cube.go b/mlp/cube.go new file mode 100644 index 0000000..c5aa1b8 --- /dev/null +++ b/mlp/cube.go @@ -0,0 +1,5 @@ +package mlp + +type Cube struct { + +} diff --git a/pack.go b/pack.go index b4161a9..cc4c3ab 100644 --- a/pack.go +++ b/pack.go @@ -1,10 +1,6 @@ package draft // import "git.fromouter.space/mcg/draft" -import ( - "math/rand" -) - -// Pack is a collection of cards from a booster pack +import "math/rand" // Pack is a collection of cards from a booster pack type Pack []Card // Card is a single card @@ -36,7 +32,8 @@ type AlternateProvider struct { } // MakePack makes a booster pack from a given schema -func MakePack(schema PackSchema) Pack { +func MakePack(set Set) Pack { + schema := set.PackSchema() pack := make(Pack, 0) for _, slot := range schema.Slots { // Default provider diff --git a/set.go b/set.go new file mode 100644 index 0000000..ef1b1bc --- /dev/null +++ b/set.go @@ -0,0 +1,69 @@ +package draft + +import "math/rand" + +// Set is an interface for all game sets/expansions +type Set interface { + PackSchema() PackSchema +} + +// GenericSet is an generalized set of a card game +// Treat this as an example implementation or a starting +type GenericSet struct { + Cards []Card + PackSize int +} + +// PackSchema returns the pack schema from a booster containing all possible cards +func (g *GenericSet) PackSchema() PackSchema { + return PackSchema{ + Slots: []PackSlot{ + {Amount: g.PackSize, Provider: g.RandomProvider()}, + }, + } +} + +// RandomProvider returns a provider for random cards from the set +func (g *GenericSet) RandomProvider() CardProvider { + return func(n int) []Card { + out := make([]Card, n) + for n := range out { + idx := rand.Intn(len(g.Cards)) + out[n] = g.Cards[idx] + } + return out + } +} + +// GenericCube is a "consumable" set, meaning cards get taken out of the pool as they are put in packs +type GenericCube struct { + Cards []Card + PackSize int +} + +// PackSchema returns the pack schema from a booster containing all possible cards +func (c *GenericCube) PackSchema() PackSchema { + return PackSchema{ + Slots: []PackSlot{ + {Amount: c.PackSize, Provider: c.RandomProvider()}, + }, + } +} + +// RandomProvider returns a provider for random cards from the set +func (c *GenericCube) RandomProvider() CardProvider { + return func(n int) (out []Card) { + c.shuffle() + if len(c.Cards) < n { + n = len(c.Cards) + } + out, c.Cards = c.Cards[:n], c.Cards[n:] + return + } +} + +func (c *GenericCube) shuffle() { + rand.Shuffle(len(c.Cards), func(i, j int) { + c.Cards[i], c.Cards[j] = c.Cards[j], c.Cards[i] + }) +}