Compare commits
2 commits
8dab3f112f
...
f983ffb93d
Author | SHA1 | Date | |
---|---|---|---|
f983ffb93d | |||
a5c9f40331 |
12 changed files with 145 additions and 31 deletions
|
@ -1,6 +1,8 @@
|
|||
# draft
|
||||
|
||||
Generic library for generating "booster packs" with randomizable slots for foils and special rares.
|
||||
Generic library for generating "booster packs" and drafting them in pods.
|
||||
|
||||
Booster packs allow for randomizable slots for foils and special rares.
|
||||
|
||||
The base library has generalized implementations of sets (think booster packs from boxes) and cube (which takes off cards from a list as they are put in packs).
|
||||
|
||||
|
|
20
draft.go
Normal file
20
draft.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package draft // import "git.fromouter.space/mcg/draft"
|
||||
|
||||
// PackProvider is a function that returns one or more packs, used for pods
|
||||
type PackProvider func() []Pack
|
||||
|
||||
// PacksFromSet is a PackProvider for a set
|
||||
func PacksFromSet(count int, set Set) PackProvider {
|
||||
return PacksFromSchema(count, set.PackSchema())
|
||||
}
|
||||
|
||||
// PacksFromSchema is a PackProvider for a schema
|
||||
func PacksFromSchema(count int, schema PackSchema) PackProvider {
|
||||
return func() []Pack {
|
||||
packs := make([]Pack, count)
|
||||
for i := range packs {
|
||||
packs[i] = MakePackWithSchema(schema)
|
||||
}
|
||||
return packs
|
||||
}
|
||||
}
|
19
draft_test.go
Normal file
19
draft_test.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package draft_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
)
|
||||
|
||||
// Tests PacksFromSet
|
||||
func TestSetPackProvider(t *testing.T) {
|
||||
testProvider := draft.PacksFromSet(3, testSet)
|
||||
|
||||
for i, pack := range testProvider() {
|
||||
t.Logf("Test pack #%d contains: %s\n", i, pack)
|
||||
if len(pack) < PACKSIZE {
|
||||
t.Fatalf("Expected %d cards in pack #%d but got %d\n", PACKSIZE, i, len(pack))
|
||||
}
|
||||
}
|
||||
}
|
0
go.sum
Normal file
0
go.sum
Normal file
|
@ -1,7 +1,6 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
|
@ -57,7 +56,7 @@ func TestAlternates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
if prurfound {
|
||||
fmt.Printf("PR Ultra Rare found after %d packs\n", i)
|
||||
t.Logf("PR Ultra Rare found after %d packs\n", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +77,7 @@ func TestAlternates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
if cnurfound {
|
||||
fmt.Printf("CN Ultra Rare found after %d packs\n", i)
|
||||
t.Logf("CN Ultra Rare found after %d packs\n", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +91,7 @@ func TestAlternates(t *testing.T) {
|
|||
pack := draft.MakePack(eoSet)
|
||||
// Check for royal rares
|
||||
if pack[6].ID == "eo207/rr1" || pack[6].ID == "eo208/rr2" {
|
||||
fmt.Printf("EO Royal Rare found after %d packs\n", i)
|
||||
t.Logf("EO Royal Rare found after %d packs\n", i)
|
||||
eorrfound = true
|
||||
break
|
||||
}
|
||||
|
|
|
@ -191,3 +191,17 @@ func DefaultI8PSchema() I8PSchema {
|
|||
{Amount: 1, Type: I8PTypeAll},
|
||||
}
|
||||
}
|
||||
|
||||
// PackProvider returns a PackProvider for a given number of main and problem packs
|
||||
func (c *I8PCube) PackProvider(mainPacks, problemPacks int) draft.PackProvider {
|
||||
return func() []draft.Pack {
|
||||
packs := make([]draft.Pack, mainPacks+problemPacks)
|
||||
for main := 0; main < mainPacks; main++ {
|
||||
packs[main] = draft.MakePack(c.Main)
|
||||
}
|
||||
for problem := 0; problem < problemPacks; problemPacks++ {
|
||||
packs[mainPacks+problem] = draft.MakePack(c.Problems)
|
||||
}
|
||||
return packs
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
|
@ -38,9 +37,9 @@ func TestDraftI8PCube(t *testing.T) {
|
|||
t.Errorf("Expected 2 cards in pack 3 but got %d", len(pack3))
|
||||
}
|
||||
|
||||
fmt.Printf("Cards in pack1: %s\n", pack1)
|
||||
fmt.Printf("Cards in pack2: %s\n", pack2)
|
||||
fmt.Printf("Cards in pack3: %s\n", pack3)
|
||||
t.Logf("Cards in pack1: %s\n", pack1)
|
||||
t.Logf("Cards in pack2: %s\n", pack2)
|
||||
t.Logf("Cards in pack3: %s\n", pack3)
|
||||
}
|
||||
|
||||
// TestDryCube tries drying up the cube to make the "OtherProvider" not able to pick a card
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
|
@ -27,8 +26,8 @@ func TestSet(t *testing.T) {
|
|||
t.Errorf("Expected 12 cards in pack 2 but got %d", len(pack2))
|
||||
}
|
||||
|
||||
fmt.Printf("Cards in pack 1: %s\n", pack1)
|
||||
fmt.Printf("Cards in pack 2: %s\n", pack2)
|
||||
t.Logf("Cards in pack 1: %s\n", pack1)
|
||||
t.Logf("Cards in pack 2: %s\n", pack2)
|
||||
}
|
||||
|
||||
// TestWrongSet tries to fetch a set that doesn't exist
|
||||
|
|
2
pack.go
2
pack.go
|
@ -1,4 +1,4 @@
|
|||
package draft // import "git.fromouter.space/mcg/draft"
|
||||
package draft
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
|
26
pod.go
Normal file
26
pod.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package draft
|
||||
|
||||
// Pod is a group of players drafting packs/cubes
|
||||
type Pod struct {
|
||||
Players []*Player
|
||||
}
|
||||
|
||||
// Player is a single player partecipating in a pod
|
||||
type Player struct {
|
||||
Packs []Pack
|
||||
Picks []Card
|
||||
}
|
||||
|
||||
// MakePod creates a pod with a specified number of players and a given set of packs
|
||||
func MakePod(playerCount int, provider PackProvider) *Pod {
|
||||
players := make([]*Player, playerCount)
|
||||
for i := range players {
|
||||
players[i] = &Player{
|
||||
Packs: provider(),
|
||||
Picks: []Card{},
|
||||
}
|
||||
}
|
||||
return &Pod{
|
||||
Players: players,
|
||||
}
|
||||
}
|
34
pod_test.go
Normal file
34
pod_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package draft_test
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
)
|
||||
|
||||
// Tests that a pod can be created and seeded correctly
|
||||
func TestCreatePod(t *testing.T) {
|
||||
const PacksPerPlayer = 3
|
||||
const PlayersPerPod = 5
|
||||
|
||||
// Get provider for test set
|
||||
testProvider := draft.PacksFromSet(PacksPerPlayer, testSet)
|
||||
|
||||
// Create pod
|
||||
pod := draft.MakePod(PlayersPerPod, testProvider)
|
||||
|
||||
if len(pod.Players) != PlayersPerPod {
|
||||
log.Fatalf("Expected %d players in pod but got %d\n", PlayersPerPod, len(pod.Players))
|
||||
}
|
||||
|
||||
for i, player := range pod.Players {
|
||||
t.Logf("Player #%d:", i)
|
||||
for packi, pack := range player.Packs {
|
||||
t.Logf(" - Pack #%d: %s", packi, pack)
|
||||
}
|
||||
if len(player.Packs) != PacksPerPlayer {
|
||||
log.Fatalf("Player #%d has %d packs but should have %d\n", i, PacksPerPlayer, len(player.Packs))
|
||||
}
|
||||
}
|
||||
}
|
38
set_test.go
38
set_test.go
|
@ -8,16 +8,27 @@ import (
|
|||
"git.fromouter.space/mcg/draft"
|
||||
)
|
||||
|
||||
const PACKSIZE = 5
|
||||
|
||||
// Test set that can be used by tests that don't need special features (like alternates)
|
||||
var testSet = &draft.GenericSet{
|
||||
Cards: []draft.Card{{ID: "a"}, {ID: "b"}, {ID: "c"}},
|
||||
PackSize: PACKSIZE,
|
||||
}
|
||||
|
||||
// Test cube that can be used by tests that don't need special features
|
||||
var testCube = &draft.GenericCube{
|
||||
Cards: []draft.Card{
|
||||
{ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, {ID: "e"},
|
||||
{ID: "f"}, {ID: "g"}, {ID: "h"}, {ID: "i"},
|
||||
},
|
||||
PackSize: PACKSIZE,
|
||||
}
|
||||
|
||||
// TestSetRepeatable makes sure that a set can generate more cards than it contains
|
||||
func TestSetRepeatable(t *testing.T) {
|
||||
const PACKSIZE = 5
|
||||
s := &draft.GenericSet{
|
||||
Cards: []draft.Card{{ID: "a"}, {ID: "b"}, {ID: "c"}},
|
||||
PackSize: PACKSIZE,
|
||||
}
|
||||
|
||||
// Create a pack
|
||||
pack := draft.MakePack(s)
|
||||
pack := draft.MakePack(testSet)
|
||||
|
||||
if len(pack) < PACKSIZE {
|
||||
t.Errorf("Pack expected to contain %d cards, contains %d", PACKSIZE, len(pack))
|
||||
|
@ -77,17 +88,8 @@ func TestAlternateProviders(t *testing.T) {
|
|||
|
||||
// TestCubeOverflow makes sure cubes stop providing cards as they are exhausted instead of going out of bound
|
||||
func TestCubeOverflow(t *testing.T) {
|
||||
const PACKSIZE = 5
|
||||
c := &draft.GenericCube{
|
||||
Cards: []draft.Card{
|
||||
{ID: "a"}, {ID: "b"}, {ID: "c"}, {ID: "d"}, {ID: "e"},
|
||||
{ID: "f"}, {ID: "g"}, {ID: "h"}, {ID: "i"},
|
||||
},
|
||||
PackSize: PACKSIZE,
|
||||
}
|
||||
|
||||
pack1 := draft.MakePack(c)
|
||||
pack2 := draft.MakePack(c)
|
||||
pack1 := draft.MakePack(testCube)
|
||||
pack2 := draft.MakePack(testCube)
|
||||
|
||||
// Pack 2 can only contain 4 cards, as there are not enough cards to fill it
|
||||
if len(pack2) >= PACKSIZE {
|
||||
|
|
Loading…
Reference in a new issue