Start adding actual drafting stuff
This commit is contained in:
parent
a5c9f40331
commit
f983ffb93d
8 changed files with 117 additions and 2 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
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
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))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue