draft

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package draft is the ban-and-pick that runs before a PvP match: who a draft may seat, and the arithmetic that says whether a format can be drafted at all.

It sits beside internal/room and lives under the same rules, for the same reason. A draft is a **pure function of the decisions taken**, so a client can replay one from the decisions alone and the server needs to send nothing else; a clock or an entropy source here would break that mirror exactly as it would in a room. TestTheDraftReadsNoClock refuses both by import.

Why a shortfall is a refused configuration and never a runtime failure

Every ban and every pick takes exactly one character out of the shared pool, and a ban is optional — a side that leaves a slot unspent takes out **fewer**. So the removals a whole draft can make are at most `2*PicksPerSide + 2*BansPerSide`, which is the number Fits requires the pool to hold. A draft that Fits allowed therefore cannot run dry: before the k-th of at most that many decisions at most k-1 characters are gone, so at least one is left for the decision about to be taken, and the pool never falls below the picks the two sides still owe.

The consequence is worth stating plainly, because the design record used to say the opposite: **there is no "the pool would no longer seat both sides" rule to write.** Optional bans can only ever help, so the worst case is the one where every ban is spent, and that is precisely the case Fits is computed against. Nothing here, and nothing in the state machine above it, has to refuse a ban or grey a slot at runtime. TestNoDraftThatFitsCanRunOutOfCharacters drives that exhaustively, and TestADraftThatDoesNotFitCanRunOutOfCharacters is the half that proves the walk can see the failure it says never happens.

None of it depends on the order the decisions come in — bans first, picks first or interleaved all remove one character apiece — so the sequence is the state machine's business and not this file's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BansPerSide

func BansPerSide(format wire.Format) int

BansPerSide is how many characters a side may ban: two at 3v3, three at 5v5. Mirrored, and **optional** — a side may leave every slot unspent.

Settled in TODO.md § "Ban and pick" (b), and read as *a side* rather than as a total across both, which is what "three bans, mirrored" meant when it was first settled.

⚠️ An unknown format answers nought, and that is no answer rather than "a format with no bans" — the same shape wire.Format.Units() has, which answers 4 for a Format(4) the game does not offer. Format.Valid is the gate for both, and Fits is where this package applies it, so a caller doing this arithmetic without going through Fits is a caller that never asked whether its format exists.

func Fits

func Fits(poolSize int, format wire.Format) error

Fits reports whether a format can be drafted out of a pool this size, and names the shortfall in characters when it cannot.

It measures against every ban being **spent**, which is the worst case and so the only one worth refusing: bans are optional, a side that skips one takes fewer characters out, and a draft this allows provably cannot run out of characters partway through — see the package comment for the argument and the test that drives it.

The refusal is therefore deliberately stricter than the arithmetic strictly needs — a 5v5 in which both sides happened to skip every ban would sit inside a pool of fifteen — and that is the trade being taken on purpose. A configuration refused when the room opens beats a draft that fails halfway through, and the alternative costs a runtime rule in every step above this one.

func PicksPerSide

func PicksPerSide(format wire.Format) int

PicksPerSide is how many characters a side picks, which is the format's own unit count: a drafted squad is the squad it fights with.

func Slack

func Slack(poolSize int, format wire.Format) int

Slack is what the pool has left over once both sides have picked and spent every ban: `poolSize - 2*PicksPerSide - 2*BansPerSide`. It goes negative for a pool that cannot seat the format, which is what Fits reports.

⚠️ It is worth drawing even when it is comfortable, because **the last pick is not a decision whenever slack is nought**: a draft whose final pick has one candidate should say so rather than present a list of one.

Types

type Config

type Config struct {
	// Format is how many units a side, which is how many picks a side and — via
	// BansPerSide — how many bans.
	Format wire.Format
	// Pool is the characters this draft may seat, fixed for the whole of it.
	Pool Pool
	// First is the seat that decides first, in **both** stages. The host is what
	// a room will pass; it is a parameter because who goes first is a fact about
	// the room rather than about the draft, and because a bo3 draft (its own
	// TODO.md item) may well want the loser of the previous battle.
	First wire.Seat
}

Config is everything a draft is set up with, and every one of these is settled before the first decision is asked for.

⚠️ There is no clock in it and there is no clock anywhere in this package — TestTheDraftReadsNoClock holds that by import. The allowance a draft runs under is counted down by whoever owns the transport, exactly as a room's is, and it arrives here as TimedOut.

type Draft

type Draft struct {
	// contains filtered or unexported fields
}

Draft is the ban-and-pick in progress: whose decision is due, what the pool has left, what each side has taken, and the record of every decision so far.

It holds state and nothing else does — the same division internal/room keeps. Nothing in it is a clock, a source of entropy or a map that reaches an output, so a draft is a pure function of the decisions taken and a client replaying those decisions computes exactly this.

func New

func New(config Config) (*Draft, error)

New sets a draft up, or says why it could never finish.

⚠️ **A draft that cannot be completed is refused here and never discovered halfway through**, which is the whole arrangement this package rests on: Fits measures the pool against every ban being spent, and the package comment carries the proof that a draft Fits allowed cannot run dry whatever order the decisions come in and whichever bans are skipped. So there is no pool exhaustion rule anywhere below this line, and adding one would be re-adding the branch #304 deleted.

func (*Draft) Apply

func (d *Draft) Apply(entry wire.DraftEntry) error

Apply takes one recorded decision back through the decision it names, which is the whole of how a draft is mirrored: a client handed nothing but the entries out of a wire.Drafted computes exactly the draft the room holds, because a draft is a pure function of the decisions taken and its pool.

⚠️ **It lives here rather than beside each caller, and that was the plan before there was a second caller.** The switch was written in record_test.go — the replay proof needed it and nothing else did — with a comment saying that the day a client mirrored a draft there would be two copies and it would belong in this package. This is that day. A client holding the switch would be a second declaration of the draft's own sequence, which is the mistake cast.ChooseLoadout was pulled together out of three copies of. → CLAUDE.md § "One rule, one declaration".

⚠️ **Every refusal is the state machine's own**, unreworded: this function routes and does not judge. A decision out of turn, of the wrong step, naming a character out of the pool, an illegal loadout and a refused arrangement all come back in the words Ban, Pick, Loadout, Arrange and TimedOut already use — so a mirror that diverged is told why in the same sentence the room would use, and there is no second reading of the rules to drift from the first.

⚠️ **The arrange phase replays one entry at a time and still ends in the same place**, which is worth knowing before reading a cursor. The two arrangements are recorded together in seats order, so applying the first one puts the *host's* arrangement in however the two really arrived — a mirror is therefore briefly waiting on the seat the room was not, and the two agree again the moment the second is applied. The phase's *end* replays exactly; its middle is not a fact two peers could agree about, since arrival order is a race. → Draft.Arrange, and TestARecordReplaysIntoTheSameDraft, which defers exactly one comparison and counts the deferral.

An unknown step is an error rather than a decision quietly dropped: a mirror that skipped a decision it did not recognise would carry on computing a draft that is no longer the room's, which is the silent desync every part of this package is arranged against.

func (*Draft) Arrange

func (d *Draft) Arrange(seat wire.Seat, slots []hex.Offset) error

Arrange is one seat's whole arrangement: the cell each of its picks stands on, in pick order, so `slots[i]` is the cell for `Picks()[seat][i]` and a caller does not have to name anybody.

⚠️ **A side arranges in one call and not a slot at a time.** The phase is simultaneous and secret, so a slot-by-slot stream would need exactly the same buffer and would additionally give a peer a *partial* arrangement to be told about. One call is also what makes "append both together" fall out of the design rather than be arranged for: there is one moment per side at which anything could be recorded, and the second of the two is when both are.

⚠️ **Nothing reaches the record until both arrangements are in**, and then both go in at once, in **seats** order rather than arrival order. An entry is public the moment it is appended and a mirror replaying the record computes the state, so appending the first arrangement when it arrives *is* showing it to the other player — the one thing this phase exists to prevent. Arrival order is a race, so recording it would make two peers' records differ for a draft in which the same decisions were taken; the price is that the record cannot say who arranged first, which is a fact a mirror has no use for. → Draft.arranged, and wire.DraftDecision.Slots.

⚠️ **The legality of the arrangement is placement.Squad.Validate's answer and its words are kept**, behind a lead-in naming the seat. That function already refuses an empty squad, more than five, a blank or duplicated unit id, a level outside the range, a cell off the 3x3 and two units on one cell — so there is no duplicate-cell rule and no off-the-board rule written here. The lead-in is there for the reason Loadout's is: two arrangements are pending at once, so a sentence naming only the unit would not say whose arrangement was turned away. → CLAUDE.md § "One rule, one declaration".

func (*Draft) Arranging

func (d *Draft) Arranging() bool

Arranging reports whether the arrange phase is open: the picking is over and at least one side has still to arrange.

It is the phase's own accessor rather than a step out of Turn, because two decisions are pending at once and Turn answers one. → Turn.

func (*Draft) AwaitingArrangement

func (d *Draft) AwaitingArrangement() []wire.Seat

AwaitingArrangement is which seats have still to arrange, in the order a room hands seats out, and nil when the phase is not open at all — a draft still picking, one that is done, and one that was cancelled.

⚠️ **It is derived from the seats array and never from a map**, for the reason seatCount is an array: a map range would randomise the order, and here that order reaches an output directly — a screen naming who the phase is waiting on, and this package's own refusals.

func (*Draft) Ban

func (d *Draft) Ban(seat wire.Seat, characterID string) error

Ban takes a character out of the pool for the whole match.

A ban lasts the match and the first cut is bo1 only — TODO.md § "Ban and pick" (d) — so nothing here has a series in it.

func (*Draft) Bans

func (d *Draft) Bans() [seatCount][]string

Bans is the characters each side took out of the pool, in the order the bans were taken, indexed by seat the way Picks is — **[0] is wire.SeatHost and [1] is wire.SeatGuest**.

⚠️ **A skipped ban is nowhere in this answer, and that is the honest shape rather than a loss.** A skip names nobody, so there is no character to list; what a skip spends is a *slot*, which is a count and not a name. A caller that wants "how many of this seat's ban slots are gone" is asking a different question from "which characters did this seat take out", and answering both through one slice would need a sentinel — the empty string standing for a real decision, which is the mistake this repository has paid for twice. So this answers the names, `BansPerSide` is the cap, and a slot spent on nobody is the difference between the two.

⚠️ **It exists because a mirror cannot derive it and a screen has to draw it.** The remaining pool is Candidates and the picks are Picks, so "banned" is already reachable as the set difference — but *by which side* is not: bans alternate from Config.First, so the sequence would have to be reconstructed from a count that skips also move, and a screen doing that arithmetic would be a second declaration of the ban order. It is read off `spent`, which is where the seat that took a character out is already recorded.

Fresh slices, like every other list this package hands out.

func (*Draft) Cancelled

func (d *Draft) Cancelled() bool

Cancelled reports whether the draft was abandoned, which today happens for exactly one reason: an allowance ran out. → TimedOut.

func (*Draft) Candidates

func (d *Draft) Candidates() []cast.Character

Candidates is what the open decision may choose from: the pool minus every character already banned or picked, in the pool's own order.

⚠️ **It is not a convenience.** With every ban spent the final pick of a 5v5 sees exactly `slack + 1` candidates, and slack was **nought** on the shipped cast when this was written — a list of one, live behaviour rather than a hypothetical. `pokemon.pichu` took it to one on 2026-09-05, so the last pick is a decision again; the shape stays because the next format or the next hidden character puts it back, and a screen owes a player the difference between choosing and being told either way. → TODO.md's slack note, and TestTheLastPickOfAFiveASideChoosesFromSlackPlusOne.

A loadout chooses a form and a kit rather than a character, so it has no candidates and the answer is **nil**. Nil is also the answer when nothing is due at all, and it is a different answer from an empty list: an empty candidate list would mean a decision with nothing to take, which step 1 proved unreachable for a draft that Fits allowed.

func (*Draft) Done

func (d *Draft) Done() bool

Done reports whether the **whole** draft is over: the ban-and-pick played out and both sides arranged. It is the state in which Squads answers, which is the question a caller asking this is about to ask next.

A cancelled draft is not done, for the reason Picked gives.

func (*Draft) Loadout

func (d *Draft) Loadout(seat wire.Seat, form string, skills, passives []string) error

Loadout is the second half of a pick: the form the character fields, four of the skills it knows at the cap as that form, and one trait.

form is progression.Furthest — the empty string — for "the furthest the cap reaches", which is what a line that does not fork means and what every placement meant before one could choose. ⚠️ **On a line that forks there is no such thing**, and pokemon.poliwag is in the shipped pool: it reaches both Poliwrath and Politoed at the cap, so an unnamed form has no answer, the refusal is progression's own, and the resulting placement would not be fieldable at all.

⚠️ **The legality of the kit is cast.ChooseLoadout's answer and its error is passed through unreworded.** That function is this repository's single declaration of "may this unit bring that skill" — its own comment records it having existed three times before it was one — and a state machine phrasing its own refusal here would be the fourth. → CLAUDE.md § "One rule, one declaration". The form's resolution gets a lead-in naming the pick and keeps progression's own words behind it, which is exactly what cast.resolveBuild does with the same call.

func (*Draft) Pick

func (d *Draft) Pick(seat wire.Seat, characterID string) error

Pick takes a character for this side. It is the **first** of the two decisions a pick is made of: the character leaves the pool now and the loadout follows, which is why Turn asks for a loadout immediately afterwards and refuses everything else until it arrives.

The split is forced rather than chosen. cast.Character.SkillsAt cannot be asked without a form, so the form belongs to the loadout — and the on-the-spot path in decision (a) is a whole screen's worth of choosing, which cannot be a single call.

func (*Draft) Picked

func (d *Draft) Picked() bool

Picked reports whether the ban-and-pick was played out: every ban spent or skipped, every pick taken and every pick's loadout chosen.

⚠️ **This is what Done used to mean, and the rename was taken rather than left.** Adding the arrange phase gave "is this draft over" two answers, and the dangerous one is the one a caller reaches for before fielding a squad — so Done is the whole thing now (picking *and* arrangement, the state in which Squads answers) and this is the narrower half it was split from. What is written against Picked is exactly what was written against the old Done: Turn closes on it, Arranging opens on it, and Picks is what it produces. The alternative — leaving Done alone and adding a third name for the whole — was less churn and left Done naming a draft nothing can field.

A cancelled draft is **not** picked and not done. It has no rosters, so a caller that treated them as one would field a side nobody picked.

func (*Draft) Picks

func (d *Draft) Picks() [seatCount][]Pick

Picks is what the ban-and-pick produces: each side's characters and the loadouts they were taken in. → Picked, which is the state in which it is complete, and Squads, which is these picks with a cell each.

Indexed by seat in the order a room hands seats out — **[0] is wire.SeatHost and [1] is wire.SeatGuest**, whichever of the two decided first. It is an array rather than a map for the reason seatCount is an array; the type is `[2][]Pick` because seatCount is two.

⚠️ **This is deliberately not a pair of squads**, and Pick's own comment says why and what the missing half is: the slot is the arrange phase's decision and Squads is where the two meet. Picks stays the shape it is because the *order* here is the order the picks were taken, which is what Arrange's slice is indexed by — `slots[i]` is the cell for `Picks()[seat][i]`.

It is safe to read mid-draft and answers what has been taken so far, including a pick whose loadout is still open — a pick with no skills, which Turn is what reports. Copies out, so a caller cannot edit the draft's own picks.

func (*Draft) Since

func (d *Draft) Since(cursor int) ([]wire.DraftEntry, int)

Since returns the entries recorded from cursor onward, and the cursor to pass next time.

A consumer holds its own cursor and nothing else, which is the shape battle.Since already has and the reason it is copied rather than a Drain: **a draft owes its record to two players and a spectator**, so a single-consumer cursor that emptied what it read would let whichever of them read first decide what the others never see. `Since(0)` is a consumer that wants everything, which is what a spectator joining a draft in progress is.

It **panics** on a cursor the record cannot answer, deliberately rather than defensively and for battle.Since's own reason: answering an out-of-range cursor with an empty slice would make a consumer that has somehow got ahead of the draft look exactly like one that is up to date, which is the silent desync a cursor exists to prevent — and a cursor is a number this method handed the caller itself, so a bad one is a programming error rather than a runtime condition.

⚠️ **The copy is of the slice, not of the entries.** An entry carries two slices of its own and they stay shared, which is the depth Pool.All hands out at as well; what this stops is a caller changing the record's shape. Recording clones what a caller named (→ Loadout), so what is shared here is a list nobody outside this package still holds a reference to.

func (*Draft) SkipBan

func (d *Draft) SkipBan(seat wire.Seat) error

SkipBan spends a ban slot without banning anybody.

⚠️ **A skipped ban leaves the character in the pool because it names none** — bans are optional, per TODO.md § "Ban and pick" (b), and a skip takes **nought** characters out. That is the direction that matters: optionality can only ever leave the pool fuller than Fits measured, which is why it cannot turn a legal room into a draft that runs dry.

func (*Draft) Squads

func (d *Draft) Squads() [seatCount]placement.Squad

Squads is what a whole draft produces: each side's picks as a fieldable squad, indexed by seat in the order a room hands seats out — **[0] is wire.SeatHost and [1] is wire.SeatGuest**, whichever of the two decided first.

⚠️ **It answers only once Done**, and until then it answers two squads with nobody in them. That is deliberately an *honestly incomplete* output rather than a plausible one: hex.Offset's zero value is a real cell, so a squad built out of unarranged picks would look authored and would then be refused at the moment it was fought, naming a cell nobody chose. A squad with no units is refused by Validate's own first line, by name. → Pick.

⚠️ **The units are ordered by SLOT, and that order decides who wins a speed tie.** atb.Queue.Add assigns seq in the order it is handed the roster and seq is the last tie-break in the turn order, so the slice order is worth up to sixty points of win rate in a mirror (CLAUDE.md § the layer rule, and wire.Start.Roster's own comment). → squadAt for which order and why that one.

func (*Draft) TimedOut

func (d *Draft) TimedOut(seat wire.Seat) error

TimedOut tells the draft that the allowance for the open decision ran out, and **cancels the whole draft**.

⚠️ It is an **input**, exactly as internal/room's is: this package does not know how long anything took and does not ask, so nothing here reads a clock and a replay cannot tell a timed-out draft from any other by anything except the entry that says so.

⚠️ **There is no auto-pick and no default**, which is TODO.md § "Ban and pick" (c) and the one place the design does not follow "a timeout announces and passes": a side that never picked has no squad to fight with, so the match starts over from a new code. A defaulted pick would hand somebody a squad they did not choose and call it theirs.

A timeout for a seat the draft is not asking is **refused**, and what the refusal protects is the decision: a transport reporting a spurious timeout must not cancel a draft on behalf of a seat nobody is waiting on.

⚠️ **It covers the arrange phase too, where the seat it may name is any seat that has not arranged rather than the one on turn** — both are being asked at once, so both have an allowance running. A seat that has already arranged is refused for the reason above: it has answered, so there is nothing of its own left to run out.

func (*Draft) Turn

func (d *Draft) Turn() (wire.Seat, wire.DraftStep, bool)

Turn is whose decision is due and which kind, and false when nothing is: a draft whose picking is over, and one that was cancelled.

⚠️ **Turn answers one seat and one step, and it never widened for the arrange phase.** Every refusal in this package is written on there being exactly one open decision — the loadout refusal ("nothing else can be decided until the form, the skills and the trait are chosen") is that assumption spoken aloud — and two arrangements are pending at once. Widening this to answer a *set* would change every one of those refusals for the sake of one phase, so the phase is asked about through Arranging and AwaitingArrangement and this keeps answering ban / pick / loadout and nothing else. → TODO.md § "The arrange phase".

⚠️ **The false does not tell three states apart and is not meant to** — Picked, Arranging, Done and Cancelled are what a caller asks, and they exist as separate questions because only one of them has two squads to field.

A loadout's owner is derived rather than stored: it is whoever took the pick the draft is waiting on, and storing the seat beside the pick would be a second statement of one fact.

type Pick

type Pick struct {
	// Character names an entry in the cast book, and is the id the pick was
	// taken with.
	Character string
	// Level is progression.LevelCap, always.
	//
	// ⚠️ **Every drafted unit fights at the cap on its chosen form, and this is
	// where a reader will look for that.** It is not a knob: cast.ParseBuilds
	// validates every entry of builds.json at the cap on the furthest form, so a
	// draft at any other level would make every shipped build an illegal loadout
	// — which is decision (a), "a pick takes a build already in builds.json or
	// one made on the spot", broken by arithmetic. It is carried as a field
	// rather than left to be assumed so that a Pick becomes a placement by
	// copying fields rather than by a reader remembering a number.
	Level int
	// Stage is the form this pick will field, **as resolved** rather than as
	// named: on a line that does not fork the loadout may leave it out and this
	// is the one form there is, so nothing downstream has to know which sort of
	// line it came off. It is the same normalisation cast.resolveBuild does, for
	// the same reason.
	Stage string
	// Skills and Passives are the loadout, already checked against what this
	// character knows at the cap as this form — cast.ChooseLoadout's answer, and
	// its order.
	//
	// Both are empty while the pick's loadout is still open, which is a state
	// Turn reports rather than a state to be detected: a pick with no skills is
	// a character taken out of the pool whose second decision has not been made.
	Skills   []string
	Passives []string
}

Pick is one character a side took, with the loadout it took it in: a placement.Placement **minus its Slot and its ID**.

⚠️ **The slot is not a pick's decision, and this type is that decision made.** TODO.md § "Ban and pick" (g): once picking closes both sides arrange their own three (or five) **privately and simultaneously**, which is a different shape from this one — two decisions pending at once, and each side's secret until both are in. That is the arrange phase, and Arrange is where a Slot arrives.

⚠️ **So a Pick is deliberately not a placement, and Squads answers only once the phase has closed.** hex.Offset's zero value is a real cell (the ally back corner, exactly the trap wire.Act documents for its Aim), so a squad handed out with Slot left at its zero would *look* authored, and what happens to it is worse than a visible gap — placement.Squad.Validate refuses the second unit standing where the first already is, so the squad is turned away at the moment it is fought, naming a cell nobody chose. An output that cannot be used is worse than an output that is honestly incomplete, which is why Squads answers two squads with nobody in them until Done.

**What turning these into squads takes**, from this end: a Slot per pick from the arrange phase, and an ID unique within the side, which is the **character id** — a drafted side cannot double up, because the pool is exclusive. placement.Placement.ID is per squad and Squad.Take prefixes the side, so a draft has nothing to invent there. Level and Stage are already resolved here, so nothing else is owed.

⚠️ **A drafted squad cannot double up, and that does not contradict the design record — it scopes it.** CLAUDE.md records "one squad may field the same character twice" as decided *yes*, and that is about a **saved** squad. The pool is exclusive, so a drafted side gets six or ten different characters by construction: both hold, and the scope is what has to be legible.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is the characters one draft may seat: the authored cast minus the ones held back. It is fixed for the whole of a draft — what a ban and a pick take out is the state machine's business, and this is the list they take it out of.

func NewPool

func NewPool(all []cast.Character) Pool

NewPool is the cast a draft may ban and pick from: `all` minus every cast.Character.Hidden. `all` is what a caller got from cast.Book.All().

Hidden is a design statement here, not an authoring convenience

⚠️ The flag's own comment calls itself "an authoring convenience rather than a design statement", and it was exactly that while the squad builder was its only reader: holding a character back kept it off a list an author was choosing from, and a saved squad naming one stayed as valid as any other. This gate makes it a **rule of the game** — a held-back character cannot be banned, cannot be picked, and so cannot be fielded in a drafted match at all. Nothing about the flag changed; what changed is that a second reader honours it for a reason a player can feel.

It filters here rather than through a `cast.Book.Offered()` accessor, and that was decided rather than deferred — see internal/screen/squads.go's offeredCharacters, which predicted this package and asked the same question. A draft wants plain Hidden with nobody kept; the squad builder wants Hidden-minus-a-`keep`, which is a fact about the squad under edit that no book can know. An accessor would answer half of each caller and both would still write a loop around it.

⚠️ And this is not "filter Hidden everywhere": internal/screen/picker.go's CharacterOptions offers a held-back character **on purpose**, because a skill restriction that already names one has to stay authorable. The two lists share a shape and share nothing else.

The order is the book's own declaration order, and it is NOT sorted by id

⚠️ **Do not "fix" this by sorting.** Order here is a presentation choice and not a determinism one: nothing in this package iterates a map, Book.All() is already a slice, and a ban or a pick names a character by id on the wire, so the record a draft leaves does not depend on it either way. Where the order does reach is the draft screen — and five other lists in this repository (the browser, the builds screen, `hexforge list`, the squad builder's chooser and the restriction picker) are all in the book's declaration order. A draft screen that sorted would lay the cast out differently from every screen the player has just come from, which is the one thing an order can get wrong here.

⚠️ The shipped cast happens to be in id order today, so sorting it would be a no-op and a test taken against it would measure nothing. TestThePoolKeepsTheBooksDeclarationOrder uses a book of its own whose declaration order is not its id order, for exactly that reason.

func (Pool) All

func (p Pool) All() []cast.Character

All is the pool in the cast book's declaration order, as a copy — the same promise cast.Book.All() makes, for the same reason: a caller that sorted or appended to what it was handed would otherwise reorder the pool itself.

⚠️ The copy is of the **slice**. cast.Character carries slices of its own and cast's deep clone is unexported, so those stay shared — which is the depth `all` arrived at anyway, because NewPool's argument is what a caller got from Book.All() and that already cloned each character once out of the book. What this copy stops is a caller changing the pool's shape or its order, which is the only thing anything here does to a list.

func (Pool) Has

func (p Pool) Has(id string) bool

Has reports whether a character is in the pool, by id.

It scans rather than holding an index, and at this size that is deliberate: the collection is the whole authored cast, so the scan is free, and a map beside the slice would be a second copy of the pool that a later `range` could turn into an ordering — the one thing a draft, like a room, may not do.

func (Pool) Len

func (p Pool) Len() int

Len is how many characters the draft may seat.

Jump to

Keyboard shortcuts

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