Compare commits
No commits in common. "f983ffb93d9e08c5047dbc291e0bd1cf7d2ae597" and "8dab3f112fdef599aa677846d179693c4027363d" have entirely different histories.
f983ffb93d
...
8dab3f112f
12 changed files with 31 additions and 145 deletions
|
@ -1,8 +1,6 @@
|
|||
# draft
|
||||
|
||||
Generic library for generating "booster packs" and drafting them in pods.
|
||||
|
||||
Booster packs allow for randomizable slots for foils and special rares.
|
||||
Generic library for generating "booster packs" with 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
20
draft.go
|
@ -1,20 +0,0 @@
|
|||
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
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
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
0
go.sum
|
@ -1,6 +1,7 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
|
@ -56,7 +57,7 @@ func TestAlternates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
if prurfound {
|
||||
t.Logf("PR Ultra Rare found after %d packs\n", i)
|
||||
fmt.Printf("PR Ultra Rare found after %d packs\n", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ func TestAlternates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
if cnurfound {
|
||||
t.Logf("CN Ultra Rare found after %d packs\n", i)
|
||||
fmt.Printf("CN Ultra Rare found after %d packs\n", i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +92,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" {
|
||||
t.Logf("EO Royal Rare found after %d packs\n", i)
|
||||
fmt.Printf("EO Royal Rare found after %d packs\n", i)
|
||||
eorrfound = true
|
||||
break
|
||||
}
|
||||
|
|
|
@ -191,17 +191,3 @@ 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,6 +1,7 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
|
@ -37,9 +38,9 @@ func TestDraftI8PCube(t *testing.T) {
|
|||
t.Errorf("Expected 2 cards in pack 3 but got %d", len(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)
|
||||
fmt.Printf("Cards in pack1: %s\n", pack1)
|
||||
fmt.Printf("Cards in pack2: %s\n", pack2)
|
||||
fmt.Printf("Cards in pack3: %s\n", pack3)
|
||||
}
|
||||
|
||||
// TestDryCube tries drying up the cube to make the "OtherProvider" not able to pick a card
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mlp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.fromouter.space/mcg/draft"
|
||||
|
@ -26,8 +27,8 @@ func TestSet(t *testing.T) {
|
|||
t.Errorf("Expected 12 cards in pack 2 but got %d", len(pack2))
|
||||
}
|
||||
|
||||
t.Logf("Cards in pack 1: %s\n", pack1)
|
||||
t.Logf("Cards in pack 2: %s\n", pack2)
|
||||
fmt.Printf("Cards in pack 1: %s\n", pack1)
|
||||
fmt.Printf("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
|
||||
package draft // import "git.fromouter.space/mcg/draft"
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
|
26
pod.go
26
pod.go
|
@ -1,26 +0,0 @@
|
|||
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
34
pod_test.go
|
@ -1,34 +0,0 @@
|
|||
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,27 +8,16 @@ 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(testSet)
|
||||
pack := draft.MakePack(s)
|
||||
|
||||
if len(pack) < PACKSIZE {
|
||||
t.Errorf("Pack expected to contain %d cards, contains %d", PACKSIZE, len(pack))
|
||||
|
@ -88,8 +77,17 @@ 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) {
|
||||
pack1 := draft.MakePack(testCube)
|
||||
pack2 := draft.MakePack(testCube)
|
||||
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)
|
||||
|
||||
// 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