From b2483213f68f5aa2709b02d50e2b8c096c641442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AEittaG=20ordnasselA?= Date: Mon, 3 Jun 2019 09:24:42 +0200 Subject: [PATCH] Make I8PCube schema flexible Closes #2 --- mlp/i8pcube.go | 66 ++++++++++++++++++++++++++++++++++----------- mlp/i8pcube_test.go | 4 +-- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/mlp/i8pcube.go b/mlp/i8pcube.go index 3ecb7d5..be4b278 100644 --- a/mlp/i8pcube.go +++ b/mlp/i8pcube.go @@ -27,6 +27,15 @@ type I8PSet struct { // I8PType is a category of cards to be seeded into packs type I8PType string +// I8PSchema is a schema to seed a single I8PCube pack +type I8PSchema []I8PSchemaSlot + +// I8PSchemaSlot is a single slot of a I8PSchema +type I8PSchemaSlot struct { + Amount int + Type I8PType +} + // All types used for seeding packs const ( I8PTypeBlue I8PType = "blue" @@ -39,20 +48,24 @@ const ( I8PTypeMulti I8PType = "multi" I8PTypeEntry I8PType = "entry" I8PTypeProblem I8PType = "problem" + + // Special types + I8PTypeAll I8PType = "all" // all means "from any other non-problem type" ) // I8PPool is a pool of card divided into categories type I8PPool map[I8PType][]Card // MakeI8PCube takes an organized set of cards and sorts them into a draftable I8PCube -func MakeI8PCube(cards I8PPool) *I8PCube { +func MakeI8PCube(cards I8PPool, schema I8PSchema) *I8PCube { return &I8PCube{ - Main: makeMainSet(cards), + Main: makeMainSet(cards, schema), Problems: makeProblemSet(cards), } } -func makeMainSet(cards I8PPool) (set *I8PSet) { +func makeMainSet(cards I8PPool, schema I8PSchema) (set *I8PSet) { + // Create set with the given card pool set = &I8PSet{ Cards: I8PPool{ I8PTypeBlue: cards[I8PTypeBlue], @@ -66,20 +79,25 @@ func makeMainSet(cards I8PPool) (set *I8PSet) { I8PTypeEntry: cards[I8PTypeEntry], }, } - //TODO Make schema more flexible + // Build PackSchema from given I8PSchema + var slots []draft.PackSlot + for _, slot := range schema { + // Check for special cases + var provider draft.CardProvider + switch slot.Type { + case I8PTypeAll: + provider = set.ProviderOther() + default: + provider = set.ProviderByType(slot.Type) + } + // Add slot + slots = append(slots, draft.PackSlot{ + Amount: slot.Amount, + Provider: provider, + }) + } set.Schema = draft.PackSchema{ - Slots: []draft.PackSlot{ - {Amount: 1, Provider: set.ProviderByType(I8PTypeBlue)}, - {Amount: 1, Provider: set.ProviderByType(I8PTypeOrange)}, - {Amount: 1, Provider: set.ProviderByType(I8PTypePink)}, - {Amount: 1, Provider: set.ProviderByType(I8PTypePurple)}, - {Amount: 1, Provider: set.ProviderByType(I8PTypeWhite)}, - {Amount: 1, Provider: set.ProviderByType(I8PTypeYellow)}, - {Amount: 1, Provider: set.ProviderByType(I8PTypeNone)}, - {Amount: 2, Provider: set.ProviderByType(I8PTypeMulti)}, - {Amount: 2, Provider: set.ProviderByType(I8PTypeEntry)}, - {Amount: 1, Provider: set.ProviderOther()}, - }, + Slots: slots, } return } @@ -157,3 +175,19 @@ func (s *I8PSet) shuffle(typ I8PType) { s.Cards[typ][i], s.Cards[typ][j] = s.Cards[typ][j], s.Cards[typ][i] }) } + +// DefaultI8PSchema returns I8Pages' schema as specified in his docs +func DefaultI8PSchema() I8PSchema { + return I8PSchema{ + {Amount: 1, Type: I8PTypeBlue}, + {Amount: 1, Type: I8PTypeOrange}, + {Amount: 1, Type: I8PTypePink}, + {Amount: 1, Type: I8PTypePurple}, + {Amount: 1, Type: I8PTypeWhite}, + {Amount: 1, Type: I8PTypeYellow}, + {Amount: 1, Type: I8PTypeNone}, + {Amount: 2, Type: I8PTypeMulti}, + {Amount: 2, Type: I8PTypeEntry}, + {Amount: 1, Type: I8PTypeAll}, + } +} diff --git a/mlp/i8pcube_test.go b/mlp/i8pcube_test.go index d9ba9d6..a28e477 100644 --- a/mlp/i8pcube_test.go +++ b/mlp/i8pcube_test.go @@ -22,7 +22,7 @@ func TestDraftI8PCube(t *testing.T) { mlp.I8PTypeEntry: mockCards("e1", "e2", "e3", "e4", "e5"), mlp.I8PTypeProblem: mockCards("P1", "P2"), } - cube := mlp.MakeI8PCube(pool) + cube := mlp.MakeI8PCube(pool, mlp.DefaultI8PSchema()) pack1 := draft.MakePack(cube.Main) pack2 := draft.MakePack(cube.Main) @@ -58,7 +58,7 @@ func TestDryCube(t *testing.T) { mlp.I8PTypeMulti: mockCards("m1", "m4"), mlp.I8PTypeEntry: mockCards("e1", "e4"), } - cube := mlp.MakeI8PCube(pool) + cube := mlp.MakeI8PCube(pool, mlp.DefaultI8PSchema()) pack := draft.MakePack(cube.Main) if len(pack) != 11 { t.Errorf("Expected 11 cards in pack but got %d", len(pack))