draft

package module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2019 License: ISC Imports: 3 Imported by: 0

README

draft

Build Status

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).

The mlp subpackage contains MLP:CCG-specific code for drafting MLP:CCG packs and cubes.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInPack     = errors.New("card picked not in pack")
	ErrNoPacksLeft   = errors.New("no packs left to open")
	ErrNoPendingPack = errors.New("no packs received from other players")
)

Errors that can happen during draft

Functions

This section is empty.

Types

type AlternateProvider

type AlternateProvider struct {
	Probability float32
	Provider    CardProvider
}

AlternateProvider are Card providers that can replace one or more slots with special cards (foils, ultra rares)

type Card

type Card struct {
	ID string
}

Card is a single card

type CardProvider

type CardProvider func(int) []Card

CardProvider is a function that returns as many cards of a certain types as needed

type GenericCube

type GenericCube struct {
	Cards    []Card
	PackSize int
}

GenericCube is a "consumable" set, meaning cards get taken out of the pool as they are put in packs

func (*GenericCube) PackSchema

func (c *GenericCube) PackSchema() PackSchema

PackSchema returns the pack schema from a booster containing all possible cards

func (*GenericCube) RandomProvider

func (c *GenericCube) RandomProvider() CardProvider

RandomProvider returns a provider for random cards from the set

type GenericSet

type GenericSet struct {
	Cards      []Card
	PackSize   int
	Alternates []AlternateProvider
}

GenericSet is an generalized set of a card game Treat this as an example implementation or a starting

Example

ExampleGenericSet is an example usage of the Set APIs to make packs

package main

import (
	"fmt"

	"git.fromouter.space/mcg/draft"
)

func main() {
	// Create a set with some items
	s := &draft.GenericSet{
		Cards: []draft.Card{
			{ID: "a"},
			{ID: "b"},
			{ID: "c"},
		},
		PackSize: 5,
	}

	// Create a pack
	pack := draft.MakePack(s)

	// Print cards in pack
	for i, card := range pack {
		fmt.Printf("Card #%d: %s\n", i, card.ID)
	}
}
Output:

func (*GenericSet) PackSchema

func (g *GenericSet) PackSchema() PackSchema

PackSchema returns the pack schema from a booster containing all possible cards

func (*GenericSet) RandomProvider

func (g *GenericSet) RandomProvider() CardProvider

RandomProvider returns a provider for random cards from the set

type Pack

type Pack []Card

Pack is a collection of cards from a booster pack

func MakePack

func MakePack(set Set) Pack

MakePack makes a booster pack from a given set It's a shortcut to `MakePackWithSchema(set.PackSchema())`

func MakePackWithSchema

func MakePackWithSchema(schema PackSchema) Pack

MakePackWithSchema makes a booster pack from a given schema

func (Pack) IDs added in v0.0.3

func (p Pack) IDs() []string

IDs unwraps all the IDs from the cards in the pack

func (Pack) String

func (p Pack) String() (str string)

String encodes a pack to a list of space-separated IDs

type PackProvider

type PackProvider func() []Pack

PackProvider is a function that returns one or more packs, used for pods

func PacksFromSchema

func PacksFromSchema(count int, schema PackSchema) PackProvider

PacksFromSchema is a PackProvider for a schema

func PacksFromSet

func PacksFromSet(count int, set Set) PackProvider

PacksFromSet is a PackProvider for a set

type PackSchema

type PackSchema struct {
	Slots []PackSlot
}

PackSchema is all that's needed to generate a certain type of pack

type PackSlot

type PackSlot struct {
	Amount    int
	Provider  CardProvider
	Alternate []AlternateProvider
}

PackSlot is part of how packs are made, one or more providers provide cards for X cards of the whole pack

type Player

type Player struct {
	// Packs and picks
	CurrentPack Pack
	Packs       []Pack
	Picks       []Card
	// contains filtered or unexported fields
}

Player is a single player partecipating in a pod

func (*Player) NextPack

func (p *Player) NextPack() error

NextPack picks the next pack passed from other players

func (*Player) OpenPack

func (p *Player) OpenPack() error

OpenPack opens the next pack the player has

func (*Player) Pick

func (p *Player) Pick(pick Card) error

Pick specified what card a player has picked and gives the pack to the next player

type Pod

type Pod struct {
	Players   []*Player
	Direction PodDirection

	ReadyNextPick chan bool
	ReadyNextPack chan bool
}

Pod is a group of players drafting packs/cubes

func MakePod

func MakePod(playerCount int, provider PackProvider) *Pod

MakePod creates a pod with a specified number of players and a given set of packs

func (*Pod) NextPacks

func (p *Pod) NextPacks() error

NextPacks makes player exchange packs for the next pick

func (*Pod) OpenPacks

func (p *Pod) OpenPacks() error

OpenPacks opens the next pack of each player

type PodDirection

type PodDirection string

PodDirection is the direction packs are passed between players

var (
	PRClockwise     PodDirection = "left"
	PRAnticlockwise PodDirection = "right"
)

All rotations

type Set

type Set interface {
	PackSchema() PackSchema
}

Set is an interface for all game sets/expansions

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL