Documentation
¶
Overview ¶
Package room is a PvP match as a **state machine over messages**, with no I/O of its own: messages and prompts in, messages and decisions out.
It speaks internal/wire and declares no message of its own. It owns one *battle.Battle at a time, the series that battle is one of, and the gate a peer gets past to sit down. A Room opens no socket, starts no goroutine, takes no mutex, and — see below — reads no clock. Two fake clients therefore drive a whole match in-process, at the speed of the engine, which is the reason it was built this way round: a server with the transport in the middle of the state machine would make this the least-tested code in a repository whose whole method is measurement.
⚠️ **Registry, in this package, is the one thing here that does hold a goroutine and a mutex**, and the two are kept apart by receiver rather than by file: TestNoRoomMethodTouchesTheMutex refuses a mutex, a channel or a goroutine on any method of Room, wherever it is written. → Registry, and the note there on why it is not a package of its own.
The room reads no clock, and that is the load-bearing shape ¶
⚠️ **A timeout is an INPUT, not a reading.** The room never asks what time it is. Whoever owns the transport counts the allowance down and calls TimedOut to say it ran out, and the room applies a Pass with a single constant reason (TimeoutReason). So `time` is not imported anywhere in this package, and TestTheRoomReadsNoClock holds that mechanically with an AST walk over this directory.
⚠️ **A timeout is announced and nothing more — it does not count towards anything.** It used to: three of a seat's own allowances running out in a row forfeited the match, and TimeoutLimit, the per-seat tally and that branch are all gone. What passing the turn buys is that the match *progresses*, which is the whole point of the input — without it a room waits forever on somebody who never answers. What the counting bought was nothing the board does not already carry: a player who walks away from the keyboard loses on the board, because the opponent keeps acting and kills the passing units, and if both walk away the turn cap draws it.
The per-turn allowance is *configuration* the room carries and hands to clients on wire.Welcome. The room does not count it down and has no opinion about how long it has been.
⚠️ internal/wire's own clock test says in its comment that a room "does need a clock". That was the expectation when the protocol landed and it turned out to be wrong: handing the timeout in as an input costs nothing and buys a package with no clock in it, so this one inherits wire's ban rather than escaping it.
What is deliberately NOT in here ¶
So a reader does not go looking for it:
- **The registry of many rooms, and the one-goroutine-per-room rule.** Not in a *Room*, which is what this list is about: concurrency did not belong in the same commit as "this has no I/O", so it landed in the one after it, as Registry. A room owning its battle in one goroutine and sharing it with nothing is a property of the thing that *holds* rooms, and the mutex is the registry's. **Nothing on a Room is safe for concurrent use and nothing on it needs to be** — the registry is what makes that true rather than what makes it a problem.
- **The WebSocket**, and everything that makes a peer a peer: a connection, a seat token, a rejoin. wire.CodeRoomUnknown is the **registry's** refusal and no room ever sends it.
- **Writing the finished match out as a battle.Log.** The room holds every decision the engine took only through the engine; a log writer is another cursor over the record, which is exactly why Since exists.
- **Seating a spectator.** The *reading* half is here — Since, an append-only record of the bodies a watcher is owed, and watch.go for the whole of it — and the half that is not is everything that decides somebody is watching: the registry's Watch, the transport holding a connection with no seat, and a client that draws a match it is not playing. ⚠️ A watcher is **not** a third seat and must never become one, because the order the two seats are visited in reaches the roster and the roster decides a speed tie.
- **The contested-speed-group alternation.** → Config.HomeFor, which says what is implemented and what is deferred and why.
Reading the battle ¶
The battle is read through Battle.Since and a cursor, and ⚠️ **Drain is never called in this package** — TestNothingHereDrainsTheBattle holds that with the same walk the clock test uses. Drain empties its consumer's cursor into the battle itself, and a room with two players, a log to write and a watcher is exactly the multi-consumer case it cannot serve. There is one cursor into the battle, the one that turns a turn's events into the digest on wire.Turn; the point of reading it this way is that the other consumers need no change here and cannot disturb it.
⚠️ **A watcher does NOT get a second cursor into the battle**, and that is worth being exact about because it is the obvious move. It reads the room's own record of *bodies* (→ watch.go), not the battle's record of events: what a client is owed is the decision and the digest, and rebuilding a battle.Decision out of battle.Events would be a second derivation of a recorded string. A watcher read written against r.cursor would take the players' own events out from under them — TestAMatchPlayedWithAWatcherReadingIsTheSameMatch is the net for it.
What a client is handed, and what it is not ¶
A client is a **mirror**: it holds its own battle built from the seed and roster on wire.Start, and applies the decisions on wire.Turn. So the room hands over *decisions and digests*, never events — the client computes the events by computing the battle, and the digest is what makes that a check rather than a hope. A divergence is loud on the turn it happens.
Index ¶
- Constants
- type Admission
- type Answer
- type BattleResult
- type Config
- type Deps
- type Outbound
- type Reading
- type Registry
- func (g *Registry) Close(code wire.RoomCode) bool
- func (g *Registry) CloseAll() int
- func (g *Registry) Codes() []wire.RoomCode
- func (g *Registry) Count() int
- func (g *Registry) Deliver(code wire.RoomCode, from wire.Seat, body wire.Body) (Answer, error)
- func (g *Registry) Join(code wire.RoomCode, hello wire.Hello) (Answer, error)
- func (g *Registry) Left(code wire.RoomCode, seat wire.Seat) (Answer, error)
- func (g *Registry) Open(at netip.AddrPort, config Config, deps Deps) (wire.RoomCode, error)
- func (g *Registry) Read(code wire.RoomCode) (Reading, bool)
- func (g *Registry) Running() int
- func (g *Registry) Since(code wire.RoomCode, cursor int) ([]wire.Body, int, bool)
- func (g *Registry) TimedOut(code wire.RoomCode, seat wire.Seat) (Answer, error)
- func (g *Registry) Wait()
- type Result
- type Room
- func (r *Room) Awaiting() (wire.Seat, bool)
- func (r *Room) Config() Config
- func (r *Room) Deliver(from wire.Seat, body wire.Body) ([]Outbound, error)
- func (r *Room) Finished() bool
- func (r *Room) Join(hello wire.Hello) (Admission, []Outbound, error)
- func (r *Room) Left(seat wire.Seat) ([]Outbound, error)
- func (r *Room) Pending() *battle.Prompt
- func (r *Room) Played() []BattleResult
- func (r *Room) Result() Result
- func (r *Room) Resume(seat wire.Seat) []wire.Body
- func (r *Room) Since(cursor int) ([]wire.Body, int)
- func (r *Room) Skipped() int
- func (r *Room) TimedOut(seat wire.Seat) ([]Outbound, error)
- type Verdict
Constants ¶
const DefaultAllowance = 90
DefaultAllowance is ninety seconds a prompt, which is the figure the design record argues with rather than the one it recommends: at 34–55 decisions a battle it is sixty-eight minutes a battle and three and a half hours for a bo3. It is the default because it is what was decided; it is configuration because that argument is not settled.
const DefaultTurnCap = 400
DefaultTurnCap is the backstop a host has no reason to change: about eight times the longest battle measured on the shipped 3v3 (34–55 decisions), so it can only be reached by something genuinely endless — two units buffing themselves at each other for ever — rather than by a long fight.
const TimeoutReason = "timeout"
TimeoutReason is the note recorded on a turn the room passed because an allowance ran out, and it is a **single constant** for the reason battle.Decision's own documentation gives: two callers supplying different words for the same choice would make a replay diverge from the log it is replaying.
It travels on wire.Turn inside the decision, so the mirror records the same string rather than inventing one. ⚠️ It is not glossed yet — internal/tui prints an event's Note raw, so today it reads "timeout" in both languages. → TODO.md, under the client's wordings.
const VerdictCount = int(VerdictAbandoned) + 1
VerdictCount is the number of verdicts, so a test can walk them rather than range over the table of names and ask it whether it holds what it holds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admission ¶ added in v0.2.0
type Admission struct {
// Seat is the seat a player took, and the zero Seat for a watcher and for a
// refusal alike.
Seat wire.Seat
// Watching is the room having welcomed a **watcher**: no seat, and the match
// to be read off the record with Room.Since rather than sent.
//
// ⚠️ It is what the room **did**, not what the hello **asked for**, and the
// difference is a whole class of connection: a hello carrying Watch that is
// turned away for its version or its password is a refusal like any other,
// so this stays false and the caller may not substitute hello.Watch for it.
Watching bool
// Rejoined is this client having taken back a seat it already held rather
// than having been given a new one.
//
// ⚠️ **The transport needs to tell the two apart even though the room does
// not.** To the room a rejoin is the same seat with the same squad, so
// nothing here changes and no message goes to the other player. To the
// transport it is the difference between a seat being filled for the first
// time — which is what starts a match — and a connection returning to one
// that was being held open for it, which must not start anything and must
// cancel the window that was about to end the match.
Rejoined bool
// Rejoinable is this seat having a token, which is what makes coming back to
// it possible at all.
//
// ⚠️ **The transport cannot work this out and must not guess it.** Whether a
// room can issue tokens is Deps.Tokens, which the transport never sees, and
// holding a seat open for a client that has no way to prove it is that client
// is a minute of the other player's time spent on nothing. So the gate says
// it, once, on the admission that created the seat.
//
// It is a second boolean beside Rejoined rather than a reading of it because
// the two answer different questions at different moments: this one is "may
// this seat be come back to", asked when it is taken, and Rejoined is "was it
// just come back to", asked on every hello.
Rejoinable bool
}
Admission is what the gate did with a hello, and it exists because there are **three** answers where a wire.Seat can only express two.
A seated player is a valid Seat and a refusal is the zero Seat; a watcher is welcomed *and* takes no seat, so "the Seat is empty" now covers two outcomes that could hardly differ more — one connection is watching a match and the other is finished with this room. Telling them apart by reading the Seat is therefore the one mistake this type exists to make unavailable, and it is the same mistake one level down as a transport reading the answer out of the welcome it is about to send. → Answer, which embeds this, and wire.Hello.Watch.
type Answer ¶
type Answer struct {
// Admission is what the gate did with a Join, embedded so that the three
// outcomes are **declared once**, in the package that decides them, rather
// than restated here and kept in step by hand. It is the zero Admission on
// every other input, exactly as Room.Join reports a refusal.
//
// ⚠️ **Watching is for the transport, not for the peer**, which is the same
// division Known draws one field down. The peer already knows: it asked, and
// its welcome names no seat. What the transport has to decide is whether to
// keep this connection at all — and it cannot read that off Seat, because a
// refusal and a welcomed watcher both have none. The alternative, a transport
// reaching into Out for the wire.Welcome and asking whether *its* seat is
// empty, is a transport parsing its own output: the same mistake Known
// exists to prevent, one message down.
//
// ⚠️ And it may not be inferred from the hello either. A hello carrying
// Watch that is refused for its version or its password is a refusal like
// any other, so what the room *did* and what the client *asked for* part
// company on exactly the connections a transport must not keep.
Admission
// Out is every message the room wants sent, in order.
Out []Outbound
// Watched is the bodies a watcher is owed **because of this input**, copied
// out of the room's own record, and Cursor is where the record stands after
// it. On a Since it is instead the read the caller asked for, from the cursor
// it passed.
//
// ⚠️ **This used to be filled on a Since alone, and that could not carry the
// last body of a match.** The exchange that records the final wire.Turn is
// the exchange that finishes the room, and a finished room retires its own
// entry the moment its match ends — so a transport that answered its players
// and *then* asked for the record was asking a room that had already gone.
// Measured before it was changed: every run of a whole match handed a reader
// 62 of its 63 turns and an unknown room on the read after the last one, with
// no race to lose, because retiring beats a socket write every time. What a
// second call cannot see, the answer to the input itself can, so the record
// read rides home with the input that produced it — inside the room's own
// goroutine, before anything can retire.
//
// ⚠️ **So a transport never hands a room a cursor of its own**, which is what
// makes the hazard on Registry.Since structural rather than remembered: the
// only cursor it passes is nought, at a watcher's join, and Room.Since panics
// on a cursor its record cannot answer. A stale cursor pointed at a fresh room
// under a reissued code cannot reach the room at all.
//
// It is empty on an input that recorded nothing, which is most of them — a
// refusal, a read, a decision that opened no turn — and one Answer type
// carries every input's answer rather than each input growing a type, exactly
// as the Admission above does. → Registry.Since, and internal/room/watch.go.
Watched []wire.Body
Cursor int
// Resumed is the whole record as the **rejoining seat** would have received
// it, and is empty on every input but a hello that took a seat back.
//
// ⚠️ **It is not Watched with a different name.** Watched is what a *watcher*
// is owed because of this input, from the host's chair, and this is the whole
// record re-sided for one seat — see Room.Resume, where the Start's side is
// the reason the two cannot be one field. A transport that handed a returning
// guest the watcher's bodies would seat it on the wrong half of its own
// board, and every digest after that would disagree while both peers fought
// the same battle perfectly.
Resumed []wire.Body
// Reading is the room after the input. It is the zero Reading when Known is
// false, because there was no room to read.
Reading Reading
// Known is false when no room is running under that code, in which case Out
// is the one wire.CodeRoomUnknown refusal.
//
// It is not a second copy of that refusal: the refusal is for the *peer*,
// which reads a code and words it, and this is for the *transport*, which
// has to decide whether to keep the connection at all. A transport reading
// the code out of a message body to make that decision would be a transport
// parsing its own output.
Known bool
}
Answer is everything the registry says back to one input: the messages the room wants sent, the seat a Join handed out, and **the room as it stands after that input**.
⚠️ The Reading rides on the answer rather than being fetched afterwards, and that is forced rather than convenient. A room removes its own entry the moment its match ends — which is what keeps a finished room from lingering — so a transport that asked *afterwards* what the result was would be asking about a room that had already gone, and the result of every match would be unreachable. The answer to the input that ended the match is the only place it can be read.
⚠️ **wire.Closed does not change that**, and a reader will ask. That message is for the *peer*, which needs to know its opponent went away, and it is sent on one ending only: a match played out to its end sends nothing, because the client computes that ending itself. So the transport's own reading of any ending still has to travel here — the same division Known draws between a refusal for the peer and an answer for the transport.
type BattleResult ¶
type BattleResult struct {
// Battle is which battle of the series this was, counting from one.
Battle int
// Home is the seat enlisted first, and therefore the one on hex.SideAlly.
// It is the sixty-point fact: seq is assigned in roster order and is the
// last tie-break in the turn queue, so the home seat wins a speed tie.
Home wire.Seat
// Seed is the seed this battle was fought from, derived from the room's one
// seed and this battle's index. → Config.SeedFor.
Seed uint64
// Winner is the seat that won, and the zero Seat for any of the draws.
Winner wire.Seat
// Outcome is the engine's, exactly as the engine reported it, and it is
// battle.Undecided for a battle the turn cap stopped — because the engine
// did not conclude anything about that battle and a room writing an outcome
// the engine never produced would be a second reading of how a battle ends.
// Capped says so instead.
Outcome battle.Outcome
// Turns is how many turns the engine opened, skipped ones included.
Turns int
// Capped is the turn cap having stopped the battle rather than the engine
// finishing it. It counts as a draw in the standing, which is what "the
// outcome already carries the draws" means: the series needs to know that
// neither seat won, and it needs no new way for a battle to end to know it.
Capped bool
// Log is the battle as `hexarena --replay --verify` reads one: the seed, the
// placement it was fought with, every decision and every event from the
// opening board.
//
// It is **composed here and written nowhere**, which is the room's I/O rule
// holding rather than an omission: a room has no filesystem, so the log
// travels out on Reading.Played like every other fact about a finished
// battle and whoever has a disk decides where it goes. → `cmd/hexarena-host`
// and its -logs flag.
//
// ⚠️ **A battle nobody finished carries none.** Only close builds a
// BattleResult, and a departure goes through abandon, which records no
// result — the engine concluded nothing about that battle, and a log of a
// fight that was interrupted would re-run to a different place than it
// stopped.
//
// ⚠️ **A capped battle carries one and it verifies**, which is worth knowing
// because the log has no Ended event: what makes it re-run is that the
// record stops on the capped turn's own turn_began. → Room.record.
Log battle.Log
}
BattleResult is one battle of the series as the room recorded it.
It carries the engine's own battle.Outcome unchanged and adds nothing to it. What it adds *beside* it is the room's half of the story — which seat was home, what seed the battle was derived to, and whether the turn cap stopped it — none of which is a fact about how a battle ends.
func (BattleResult) Draw ¶
func (b BattleResult) Draw() bool
Draw reports whether the battle went to neither seat, which every ending but a victory is: annihilation, stalemate, and the turn cap.
type Config ¶
type Config struct {
// Format is how many units a side, and the gate refuses a squad that is not
// that size.
Format wire.Format
// Battles is the series length, and **bo1 is not a special case — it is
// N = 1**. Only 1 and 3 are accepted: only an even series cancels the side
// advantage, and only an even series has to invent a rule for a 1–1. The
// aggregate-health tie-break an earlier draft proposed is dropped, so no
// invented metric ships anywhere in here.
Battles int
// Allowance is how long a player has to answer one prompt, in seconds. The
// room hands it to both clients on wire.Welcome and never counts it down.
Allowance int
// Seed is the match's one seed. Every battle's seed is derived from it and
// the battle's index (SeedFor), so a whole match is reproducible from a
// single number.
Seed uint64
// TurnCap is how many turns one battle may open before the room stops
// asking, so a runaway cannot hold two people at a board for ever.
//
// ⚠️ **It rides on wire.Welcome**, beside the allowance and for the same
// reason: a cap is room configuration the client needs in order to behave
// correctly, and the client is a mirror — given the cap it stops on the same
// turn by the same arithmetic, so no message and no Ended is needed to tell
// it a battle was capped. → wire.Welcome.TurnCap, which carries the three
// alternatives that were refused.
TurnCap int
// Budget is a **chess clock**: how many seconds each player has for the whole
// match, counted only while the room is waiting on them. Nought is no budget
// at all, which is the shipped default and the arrangement every room had
// before this field.
//
// ⚠️ **It does not replace the per-turn allowance; both apply and the shorter
// one wins.** They answer different questions — the allowance stops one turn
// hanging a match, the budget stops a whole match being spent one legal turn
// at a time — and a room with a budget and no allowance would let a player
// hold a single turn for the length of their entire clock.
//
// ⚠️ **The room does not count it and cannot.** Every field here is a number
// the room passes on rather than reads: internal/room has no clock, which is
// what lets a match be driven a message at a time in a test. The transport
// spends the budget exactly as it spends the allowance, and the room learns
// the result the same way — a TimedOut input arriving.
//
// ⚠️ **Running out is not a forfeit**, which is the decision the allowance
// already took: a seat with nothing left times out on every prompt from then
// on, so its units pass and the board kills them. Nobody is declared to have
// lost on time — they lose on the board, which is where this game decides
// things. → TestASeatThatNeverAnswersLosesOnTheBoardRatherThanByForfeit.
//
// ⚠️ **It rides on wire.Welcome**, beside the allowance and the cap and for
// the same reason: a client counts its own clock down so a player can watch
// it, and a number the room enforced and never told anybody about would be a
// match lost to something invisible.
Budget int
// Password keeps strangers in the house off the board and is **not**
// security. Empty is a room with none, which accepts any hello that gets
// past the version gate.
Password wire.Password
// Drafts says the two sides **ban and pick** before they fight, out of one
// shared pool, rather than each bringing a squad it built at home. It rides
// to both clients on wire.Welcome, which is what tells a client not to bring
// one.
//
// ⚠️ **Whether the pool can seat the format is NOT checked here, and cannot
// be.** draft.Fits measures a pool against a format, the pool is the cast
// minus every character held back, and Validate is a method on this struct
// with no Deps to read a cast book out of. So that check lives in New, which
// has both — and a room whose draft could never finish therefore fails when
// it is opened rather than when somebody joins it, which is the arrangement
// internal/draft's own New rests on. Measured on the shipped cast: a pool of
// **19**, so 3v3 has nine characters to spare and 5v5 has three.
//
// ⚠️ **A series drafts once a battle**, so three battles can be three
// different squads out of three fresh pools. That was the open question this
// field's refusal used to stand in for — "what a draft means across a series"
// — and it is answered: → Room.redraft, where the pool's reset and the ban
// order are argued. Validate therefore says nothing about the two together
// any more.
Drafts bool
// Watchable says a client that asked to **watch** (→ wire.Hello.Watch) is
// welcomed rather than turned away. It is **off by default**, which is the
// shape Drafts above has: a room is for the two people in it unless the host
// said otherwise, and the flag that says otherwise is cmd/hexarena-host's
// -watch — the one place in the repository a room's configuration is chosen.
//
// ⚠️ **It is configuration and NOT watcher state, and the distinction is the
// whole reason this is a bool on this struct.** Every field here is a
// decision taken before anybody joins and never written again, and this one
// is read in exactly one place — the gate — to answer one hello. The room
// still keeps no count of watchers, no list of them and no cap, which is
// what leaves seatCount at 2, other() honestly "the other one" and the
// roster in the order it would have been in with nobody watching. How many
// are watching, and whether there is room for one more, remains the
// transport's (socket.MaxWatchers). → watch.go, and Join.
//
// ⚠️ **It deliberately does NOT ride on wire.Welcome**, unlike Drafts. A
// welcome is the settings a client needs in order to *behave correctly*, and
// Drafts is one of those because it tells a client not to bring a squad. A
// client learns this one by being answered: it asked to watch and was either
// welcomed or refused wire.CodeWatchingClosed, which is the whole of what it
// can do about it. Putting it on the welcome would be telling every seated
// player a fact about a feature they are not using. → welcomeTo.
Watchable bool
}
Config is everything a room is set up with, and every one of these is a decision the host makes before anybody joins.
⚠️ There is no clock in it and there is no clock anywhere in this package. Allowance is a *number the room carries and hands to its clients*; whoever owns the transport counts it down and tells the room when it ran out. See the package comment, and TestTheRoomReadsNoClock, which holds it mechanically.
func (Config) HomeFor ¶
HomeFor is which seat is **home** for one battle of the series: enlisted first, and therefore on hex.SideAlly.
Battles alternate, starting with the host, because which side you get is worth up to sixty points in a mirror and fighting both ways round is the only thing that cancels it. What alternation cannot cancel is a battle with no partner — bo1's only battle, and the third battle of a 1–1 bo3 — and those two are the same problem, so they get one rule: **the seed picks the side**, off the low bit of that battle's own derived seed.
⚠️ It is honestly uncancelled and the room says so rather than dressing a coin as fairness. bo3 is worse than it reads for exactly this reason: an odd series does not remove the side advantage, it concentrates it into the one battle that matters most.
⚠️ The refinement the design record pairs with this — the lead of each contested speed group alternating, which was measured at 49.6% against 54.2% for ally-first on a two-unit mirror — is **not here**. It needs the roster slice composed against the queue rather than as the squads were authored, the side is worth up to sixty points, and what it is worth at 3v3 or 5v5 is unmeasured. → TODO.md, its own item.
func (Config) SeedFor ¶
SeedFor is the seed of one battle of the series, counting from one.
The derivation is the first eight bytes of `sha256(seed ‖ index)`, both written as fixed-width big-endian integers — the same framing internal/seed and internal/wire hash their inputs under, which is why it is spelled this way rather than invented. It reads no clock and draws no randomness of its own: it is a pure function of two integers, which is what makes a whole match reproducible from one number and what will make a match log verifiable the day the room writes one out.
⚠️ **The obvious version was written first, measured, and is wrong.** Reusing the mixer rng already declares — `rng.New(Seed + index).Next()`, one round of splitmix64 — looks like exactly the right move under this repository's rule about not restating arithmetic, and it collides **structurally**: splitmix64 advances by adding a constant, so one round of it is a function of `Seed + index` alone, and battle two of a match seeded 6 *is* battle one of a match seeded 7. Two different matches sharing a battle is not a rounding error; it is the coincidence a balance run reads as a result and a bug report cannot see. Every counter-based generator has that shape, so no arrangement of rng fixes it — a derivation from *two* numbers needs a function of two numbers. TestAWholeMatchIsReproducibleFromOneNumber is what caught it, by asking the question rather than by asserting three values.
The mixing is also what makes the low bit worth reading, which is what picks the side of an uncancelled battle below.
type Deps ¶
type Deps struct {
// Books is the parsed data the battle reads.
Books battle.Books
// Characters is the cast book, which is what resolves a squad — a placement
// is a reference and Take is what turns it into units.
Characters *cast.Book
// Version is what this binary announces, and the gate checks a peer against
// it. It is passed in rather than computed here because a build string is
// stamped at build time and read by the binary's own main; wire.Local is
// what assembles one.
Version wire.Version
// Tokens makes a seat token, and is what a rejoin rests on.
//
// ⚠️ **It is injected rather than called for here, because a room has no
// randomness of its own and is not getting any.** Everything else this
// package does is a state machine over messages — no clock, no rand, no I/O —
// which is what lets the room be driven a message at a time in a test and
// replayed from a log. A `crypto/rand` read inside Join would put the first
// unrepeatable thing into it.
//
// ⚠️ **Nil is a supported answer and means no rejoin.** The room seats
// clients exactly as before and issues no token, so a caller that has not
// thought about tokens gets the behaviour it had rather than a panic or a
// half-feature. cmd/hexarena-host supplies one; a test that does not care
// leaves it nil.
Tokens func() (wire.SeatToken, error)
}
Deps is what a room is handed rather than what it decides: the parsed data, and the version this binary announces.
type Outbound ¶
type Outbound struct {
// To is the seat this message is for, and is the zero Seat on a refusal at
// the gate — refusing is what stops a seat being handed out, so there is no
// seat to name and the transport answers the connection it read the hello
// from.
To wire.Seat
Body wire.Body
}
Outbound is one message the room wants sent, and the seat it is for.
Every recipient gets its own Outbound rather than one message addressed to the room, because the two seats' messages genuinely differ: a wire.Welcome names the seat it went to, and a wire.Start carries the *side* this client plays, which is the opposite half of the board for the other one. A "send to everybody" shape would only fit the messages that happen to be identical.
type Reading ¶
type Reading struct {
// Config is what the room was opened with, which is where the allowance a
// transport counts down comes from.
Config Config
// Awaiting is the seat whose answer is due and Waiting whether the room is
// waiting on anybody at all — Room.Awaiting, which is what an allowance is
// started on.
Awaiting wire.Seat
Waiting bool
// Finished and Result are the match.
Finished bool
Result Result
// Played is a **copy** of the battles the room recorded, so that nothing but
// the room's goroutine holds a slice the room appends to.
Played []BattleResult
// Skipped is how many prompts the room walked past. → Room.Skipped for why
// it is a reading rather than a debug counter.
Skipped int
}
Reading is what a transport reads off a running room, taken inside that room's own goroutine and copied out.
⚠️ **Pending is deliberately not in it, and it is no longer a gap.** Room.Pending hands back a *battle.Prompt, which is a pointer into the room's own state, and passing one out of the goroutine is exactly the sharing this file exists to prevent. This note used to add that a rejoining client needs the open prompt and that a copy whose slices were copied too was therefore owed. **It is not.** A mirror derives the prompt: it calls Begin itself and advances to the same one after the last recorded turn, which is the same thing a watcher does and the reason no wire.Turn carries the opening board either. What travels is the decisions. → Room.Resume.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the many rooms one process runs, keyed by the code a player pastes. It is the concurrency around the room and **nothing else**: a room owns its battle in one goroutine and shares it with nothing, and the mutex that makes that true is this file's.
⚠️ **The mutex guards the map and nothing else.** It is taken to look a code up and released before anything is sent to the room it found, so N rooms in a process do not serialise through one lock. That is the whole point of the rule rather than a refinement of it: a mutex held across the send would keep the letter of "one goroutine per room" while making the process as slow as one room. There is exactly one place a request path locks — lookup — and exactly one place a request is sent — ask — and TestNoLockingFunctionSendsOnAChannel holds the two apart mechanically.
A request is a value, never a closure ¶
⚠️ A `func(*Room)` on the channel is the tidy-looking design that **defeats the invariant**: it lets the caller capture the pointer and keep it, so the room's state is reachable from a goroutine that is not its own, and nothing about the code would look wrong. So what travels is a small discriminated value — request, with an inputKind and the arguments of the matching input — the goroutine switches on it and calls the method itself, and no *Room is reachable from anywhere but that goroutine. TestTheRegistryHandsOutNoRoom is the other half of it: nothing on this type's exported surface passes one out.
The *data* is shared and that is a different thing. Deps holds the parsed books and the cast, every room reads the same copy, and none of it is written after it is parsed — what must not be shared is the *battle*.
The registry reads no clock either ¶
⚠️ Whoever owns the transport owns the countdown, and the transport is the next item — so TimedOut is **forwarded** here exactly as it is taken there, and nothing in this file starts a timer, holds a deadline or asks what time it is. `time` stays unimported across the whole package and TestTheRoomReadsNoClock keeps holding it with this file in the directory it walks, which is one of the two reasons the registry lives in internal/room rather than in a package of its own. The other is that a *Room need not leave the package at all.
What is deliberately NOT in here ¶
So a reader does not go looking for it:
- **The WebSocket.** This is the concurrency and not the transport. Nothing here opens a socket — Open takes the **address** a listener will be at, which is a value, and derives the code from it. ⚠️ That is what changed when "one listener or one per room" was decided: the registry allocates the room byte now. → the note on Open.
- **The clock**, per above.
- **Writing a finished match out as a battle.Log.** Another cursor over the battle, and the room already reads it that way so that a second consumer costs nothing.
- **Watchers, as things this file counts, lists or caps.** ⚠️ This bullet used to read *"Spectators. A third seat is a room change, not a registry one; a watcher is a cursor"*, and the second half of that is what shipped: Since is here, because a cursor over the room's record has to be read inside the room's goroutine like any other reading. What is **not** here is any notion of *who* is watching — no count, no list, no limit — because a watcher is a connection and connections are the transport's. A registry that capped them would be a registry holding a fact it cannot keep true: nothing tells it when one goes away. → TODO.md's spectator step 4.
func (*Registry) Close ¶
Close stops one room and reports whether there was one to stop. The room's goroutine ends; whatever it was in the middle of a match is not written anywhere, because nothing writes a match out yet.
func (*Registry) CloseAll ¶
CloseAll stops every room and reports how many it stopped, which is what a server's shutdown does before it Waits.
func (*Registry) Codes ¶
Codes is every code a room is running under, **sorted**, because a map's iteration order must not reach an output — the engine's rule one layer out.
func (*Registry) Deliver ¶
Deliver hands a room one message from a seated peer, by code. → Room.Deliver.
func (*Registry) Left ¶
Left forwards the transport's report that a peer went away, by code. → Room.Left.
func (*Registry) Open ¶
Open starts a room behind one address and hands back **the code a player pastes** and nothing else, because ⚠️ **a *Room must not leave the goroutine that will own it** — the registry builds one and keeps it, and the code is the only handle on it anybody gets.
The registry allocates the room byte, and that used to be the caller's job ¶
⚠️ **Open used to take the code**, and that was a decomposition forced by an open question rather than a design: the record's "a code carries its own address" and "one process runs many rooms" cannot both hold with one listener, the reading on the table was a **listener per room**, and allocating a port is I/O the registry has none of. That question is settled the other way — one listener, and the code carries a seventh byte naming the room — so the awkwardness goes with it. An address is a *value*, so the registry can take one, and wire.EncodeRoom is pure arithmetic over it. → wire.EncodeRoom for what a port per room would have cost, and README.md § A room, and getting into one.
The byte is the **lowest free** one, which is deterministic so that a test can name the code a room will be given, and it is picked under the same hold of the mutex that enrols the room, so allocating and enrolling are one atomic act rather than two with a window between them. → enrol.
A duplicate code is therefore **impossible by construction** rather than refused. What is still refused is an address a code cannot carry — an IPv6 one, or the zero AddrPort — and a 257th room behind one address, because the room is one byte wide. That last one is an **error rather than a wire.Code**: a host that cannot open another room is the host's problem, not something a joiner is told about.
func (*Registry) Read ¶
Read is the readings a transport needs, taken inside the room's goroutine, for a transport that wants to look at a room without giving it an input — the other peer's join is what starts the first allowance, and the seat waiting for it was handed no answer of its own.
It reports false for a code no room is running under, which a **finished match also is**. The result of a match is therefore read off the Answer to the input that ended it and not from here. → the note on Answer.
func (*Registry) Running ¶
Running is how many room goroutines are owed an end, which is not Count: a room that has retired its entry but not yet returned is still a goroutine. → the note on the field.
func (*Registry) Since ¶ added in v0.2.0
Since is a **watcher's** read of one room's record, by code: the bodies recorded from cursor onward, the cursor to pass next time, and whether there was a room to read at all.
It is Read's shape rather than a new one — take the reading inside the room's goroutine, copy it out, and report a code no room is running under as *not known* rather than as an empty read. That last distinction is the whole reason the bool is here and is the same one Answer.Known draws: a watcher of a room that has finished must not look like a watcher that is merely up to date, and a room removes its own entry the moment its match ends.
⚠️ **The copy is taken even though the room's own view is already safe to hand out**, and the reasoning is worth writing down because the obvious reading of it is "this copy is free to delete". Room.Since returns a three-index view, so its capacity is its length: a caller's own append reallocates instead of writing into the slot the next body is going to be recorded in, and append only ever *writes* at an index the view cannot address, so the elements a watcher reads are ones the room will never touch again — and the reply channel is the happens-before edge that makes reading them ordered. So it is safe today, and the copy is not what makes it safe today. It is taken for Reading.Played's reason: "nothing outside the room's goroutine holds a slice into memory the room owns" is a property a reader checks by reading one line, where "the aliasing is harmless because of what append does" is an argument that the first record which ever *rewrites* a recorded slot — a ring buffer put in when the bound in watch.go stops being comfortable, say — would silently invalidate.
⚠️ **An out-of-range cursor panics on the room's own goroutine**, which is Room.Since's deliberate choice and not something this hides: answering one with an empty read would make a consumer that has got ahead of the room look exactly like one that is up to date. What travels with it is a warning for whoever holds the cursors, because the blast radius is bigger here than inside one room — **a cursor is a number this registry handed out for one room, and a room's code is handed out again once its match ends** (the room byte is the lowest free one, so a finished room gives its code back). A transport that let a watcher's cursor outlive the room it came from would therefore be asking a fresh room about a record it never had. Drop the cursor with the room.
⚠️ **Step four answered that by never handing a room a cursor but nought.** A watcher's catch-up is Since(0), which is safe against any record, and every body after it rides home on the answer to the input that recorded it — so the transport's own cursors are never passed back in and a stale one cannot reach a room at all. → Answer.Watched, which is where the reason that had to change is written down.
func (*Registry) TimedOut ¶
TimedOut forwards the transport's report that an allowance ran out, by code.
⚠️ It **forwards** and does not measure. The registry no more reads a clock than the room does; the countdown belongs to whoever owns the connection. → Room.TimedOut.
func (*Registry) Wait ¶
func (g *Registry) Wait()
Wait blocks until every room's goroutine has ended.
⚠️ It waits for rooms to end **by themselves** and closes nothing, which is what makes it a measurement: a goroutine left behind by a finished match hangs this rather than being tidied up by the call that was supposed to observe it. A shutdown is therefore CloseAll then Wait, in that order and as two calls.
type Result ¶
type Result struct {
Verdict Verdict
// Winner is the seat that took the match, and is the zero Seat for a draw,
// for a match still being played **and for an abandoned one** — nobody wins
// a match nobody played out. Seat.Valid is the question to ask.
Winner wire.Seat
// Departed is the seat that went away, and the zero Seat for a match that
// was played out. It is the fact an abandoned match needs and cannot derive:
// it is not simply "the other one" the day a room holds spectators.
//
// ⚠️ It was called Loser, beside a Forfeit saying why. Nobody loses by
// leaving now, so the word had to go with the concept — a field called Loser
// on a verdict where nobody lost is exactly the stale wording this
// repository keeps a list of.
Departed wire.Seat
// Wins is how many battles each seat took, indexed the way the room indexes
// its seats. Draws count for neither, which is why the two need not add up
// to the number of battles played.
Wins [seatCount]int
// Battles is the battles actually fought, which is fewer than the series
// length whenever a seat took an unbeatable lead early.
Battles int
}
Result is the match, finished or not.
type Room ¶
type Room struct {
// contains filtered or unexported fields
}
Room is one match: a series of battles between two seats.
It is not safe for concurrent use, deliberately — see the package comment.
func New ¶
New sets a room up. It validates the configuration and the data, so a room that cannot run a match fails here rather than when somebody joins it.
⚠️ **A room that drafts builds its draft here, and that is where the pool is checked against the format** — which is the one part of the configuration Config.Validate cannot see, because draft.Fits needs a pool, a pool needs the cast book, and Validate has no Deps. So the whole question "could this room ever finish its draft" is answered by draft.New in one call: the pool seats the format, every character in it has an id, and no id is in it twice. A room whose draft could not finish therefore fails **before a code is handed out** rather than halfway through somebody's ban and pick, which is the arrangement internal/draft's package comment rests on.
func (*Room) Awaiting ¶
Awaiting is the seat whose answer is due and whether the room is waiting on anybody at all.
⚠️ **This is what a transport starts its allowance on, and it is the whole of the room's side of the clock.** It is never set across a skipped prompt, because the room walks past those itself, so "a Skipped prompt starts no clock" is a property of this state machine rather than a rule the transport has to remember. It is also false between battles and once the match is over.
⚠️ **In a room that drafts this answers the DRAFT's open decision first**, and the arrange phase — which has two decisions pending against this one seat — is serialised into it rather than widening what a reading can hold. → draftAwaiting, which carries that decision and the two things it costs.
func (*Room) Config ¶
Config is the room's configuration, for a caller that has to hand a client something it was set up with.
func (*Room) Deliver ¶
Deliver hands the room one message from a seated peer and returns everything the room says back.
It takes wire.Act, wire.Pass and wire.Decide, which are the three messages a client sends once it is in. Anything else — including a wire.Hello, which goes to Join, and any of the five server-bound bodies, which is a peer speaking the wrong direction — is answered with wire.CodeUnknownMessage, because that is what this protocol's ten codes have for a message that does not belong here.
⚠️ **`from` is where the seat comes from and it is the only place any of the three read one.** wire.Act carries no unit, wire.Pass carries nothing at all and wire.Decide carries no seat — all three by the same design — so the seat is a fact about the connection the transport read the message off, and this parameter is its one statement. → decideFrom, where that is load-bearing rather than incidental.
func (*Room) Join ¶
Join is the gate. It reports what the room did with the hello and everything the room says back; on a refusal the Admission is the zero one and the one message is a wire.Refused carrying a wire.Code.
⚠️ On a refusal the Outbound names **no seat**, because refusing is precisely what stops one being handed out — the transport answers the connection it read the hello from. ⚠️ **Seat.Valid is no longer the question to ask about the first return**, and that sentence stood here until a watcher could be welcomed: a watcher is answered with no seat too. → Admission.
The order, which is part of the answer ¶
Five checks and one exit, and the order is pinned by TestTheGateRefusesInItsOwnOrder because a gate whose order is untested is a gate that reports whichever fault it happened to notice first. A peer wrong about two things has to be told about the earlier one:
- **The version**, through wire.Version.Check, which is itself protocol before digest. A peer that cannot speak the protocol must not be told its data is wrong: it may not be able to read the refusal, and the update it needs is the binary. That ordering is tested in internal/wire and is not restated here.
- **The password**, in constant time, through wire.Password.Equal. Before the seat, so that a stranger with the wrong password learns nothing about how full the room is.
- **The watcher's exit**, where a hello that asked to watch is answered and leaves, so none of the three below is consulted about it. It sits *after* the two above and *before* the two below, and both halves of that are decisions → the branch itself. ⚠️ **This used to say "not a check at all", and watching being opt-in made that false**: the branch asks one question, Config.Watchable, and refuses wire.CodeWatchingClosed if the host did not open the room to spectators. It is a question about the room's configuration rather than about the hello, and it is asked here so that the answer is about the room rather than about the two people who may already have the seats.
- **The seat.** Before the squad, because a squad check on a full room is work done to reach an answer that was already decided — and because "your squad is illegal" is a worse thing to tell somebody who was never getting in than "the room is full".
- **The squad**, which is five rules under one code (see squadRefused) — or, in a room that **drafts**, the opposite question under a different code: there a squad is *unwanted* rather than illegal, and squadIsFieldable is not consulted at all. → the branch below, and squadIsFieldable's own note.
- Nothing else. wire.CodeRoomUnknown is the *registry's* refusal — a code naming no room this process is running — so no room ever sends it.
func (*Room) Left ¶
Left tells the room that a peer went away.
⚠️ Whether a peer has really gone or is merely slow is the **transport's** judgement and not the room's, exactly as a timeout is. A reconnect window would sit in front of this call rather than inside it — the design record holds the seat for a rejoin, and the seat token that makes a rejoin possible is its own TODO.md item — so this is the terminal case: the transport has decided.
⚠️ **Leaving announces and costs nothing.** The match ends as VerdictAbandoned, which is not a win, not a draw and not a forfeit: the seat that went away is recorded and neither seat is charged with anything. A player who is losing can therefore leave at no cost, and on a LAN between friends the enforcement of that is social — a stated cost rather than a gap. → README.md § PvP over a LAN.
Before the match starts there is no match to end, so the seat is simply freed and the room goes back to waiting for a second player. A reconnect window therefore sits **in front of** this call and not inside it — → TODO.md, under the seat token.
⚠️ **A draft in progress IS a match in progress here, and that branch had to be added rather than being already right.** A draft runs with no battle open and nothing played, so the pre-match arm below matched it: the seat was freed, the room went back to waiting for a joiner — with the departed side's bans and picks still in the draft, and the peer still there holding an open decision nobody was coming to take. That is exactly the hang abandon's own comment says a wire.Closed exists to prevent. The ending itself is unchanged: the existing ClosureLeft path, VerdictAbandoned, nobody charged with anything.
func (*Room) Pending ¶
Pending is the open turn: whose unit is acting and what it may do, which is what a server hands a client that lost track of it. Nil when nothing is open.
func (*Room) Played ¶
func (r *Room) Played() []BattleResult
Played is every battle of the series the room has recorded, in order.
func (*Room) Resume ¶ added in v0.2.0
Resume is the whole record as one seat would have received it, which is what a client that lost its socket needs in order to come back to the board it left.
⚠️ **The record cannot simply be replayed by a player, and that is the one thing about a rejoin that is not obvious.** A wire.Start carries the *side* its recipient plays, and the recorded one is taken from the host's chair on purpose — a watcher plays neither half, so it is given the seat a room hands out first. Handed unchanged to a returning **guest**, it would seat that client on the wrong half of its own board: every subsequent digest would disagree while both peers were fighting the same battle perfectly, which is the failure mode this file's Since already warns about from the other end. So each Start is re-sided here, for the seat asking.
⚠️ **The open prompt is NOT sent and does not need to be**, which retires a note that stood in TODO.md since before the record existed: a rejoin was said to want a copy of Room.Pending, because passing the room's own *battle.Prompt out of its goroutine is exactly the sharing the registry exists to prevent. A mirror does not need one. It calls Begin itself and advances to the same prompt after the last recorded turn — the same thing a watcher does, and the reason no wire.Turn carries the opening board either. What has to travel is the decisions; the prompt is derived at both ends from the same events.
The bodies themselves are not deep-copied, for watchedFrom's reason: a wire.Body is a value the room recorded and never edits. The Starts are the exception and are **replaced** rather than edited, so the record keeps the one it holds.
func (*Room) Since ¶ added in v0.2.0
Since returns the bodies recorded from cursor onward, and the cursor to pass next time.
A watcher holds its own cursor and nothing else, which is the shape battle.Since and draft.Since already have and the third copy of it rather than a new idea. `Since(0)` is a watcher that wants everything, **which is exactly what joining halfway is**: the wire.Start of the battle in progress is in the record, so a late watcher is handed the roster and the seed it needs to build its own mirror and then every turn since — with no Battle.Roster() accessor and no second copy of the roster anywhere, because begin() builds it in a local and the record holds the body.
It is a Since and **not a Drain** for internal/draft's own reason: a match owes its record to two players and however many watchers, so a single-consumer cursor that emptied what it read would let whichever of them read first decide what the others never see. Many cursors may coexist and none of them can starve another.
⚠️ **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 room 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 recorded wire.Start is built for a watcher, and its Side is the HOST's.** Everything else in it is the players' body unchanged — the same seed, the same roster in the same order, the same battle index — but Side is the half of the board *this client plays*, and a watcher plays neither. So it watches from the host's chair, which is a decision stated here rather than whatever happened to fall out of the loop: a watcher has to be given some side to draw the board from, the host is the seat a room hands out first, and the alternative — a wire.Start with no side — would be a hex.Side zero value that reads as SideAlly to everything downstream. → begin, which is the one place it is set.
The slice is a three-index view, so its capacity is its length and a caller's own append has to reallocate rather than writing into the slot the next body is going to be recorded in. → battle.Since, where that was measured to corrupt both the caller's copy and the record.
func (*Room) Skipped ¶
Skipped is how many prompts the room walked past because the unit had already lost its action. → the field's own comment for why it is exposed.
func (*Room) TimedOut ¶
TimedOut tells the room that the allowance for the open prompt ran out.
⚠️ It is an **input**. The room does not know how long anything took and does not ask; the transport owns the countdown and this is it reporting the result. What enters the battle is a Pass with TimeoutReason, never a timestamp and never a duration, so a PvP log stays exactly as verifiable as one from a battle nobody was waiting on and --verify cannot tell a timed-out match from any other.
⚠️ **It announces and nothing more: nothing is counted and nothing is forfeited.** Three in a row used to end the match, and that is gone — → the package comment for what the counting was buying and why the board already carries it. What survives is the pass, which is what makes the match progress rather than wait forever on somebody who never answers.
⚠️ **It needs no message of its own, and that is worth being exact about.** The pass carries TimeoutReason, that reason is part of the battle.Decision, and the decision goes out on wire.Turn — where Decision.Reason is tagged `json:"reason,omitempty"`. So the mirror is *already told* that the turn was lost to a clock, by the one declaration of it that travels, and a second message would be a second spelling of a fact both peers already hold. TestATimeoutTellsTheMirrorWithNoMessageOfItsOwn is what measures that rather than asserting it here.
A timeout for a seat that is not being asked anything is **refused**, and the refusal matters more than it did: with no tally to protect, what it protects is the turn itself — a transport reporting a spurious timeout must not spend the answer of a seat the room is not asking. It is also what makes a Skipped prompt untimeoutable: the room never leaves one open, so there is never an allowance to run out on one. ⚠️ **A timeout during the ban and pick does NOT pass anything — it closes the room**, which is the one place the paragraphs above do not hold, and the reason is that there is nothing honest to pass with: a side that never picked has no squad to fight with. → draftTimedOut, and wire.ClosureDraftExpired.
type Verdict ¶
type Verdict uint8
Verdict is how a **match** ended, and it is deliberately not called an outcome.
⚠️ Nothing here is added to battle.Outcome and nothing ever should be. That enum is a core type read by --verify and by every renderer, and it answers a different question: how a *battle* ended. A departure is not a way a battle can end — the battle it interrupted was in a perfectly ordinary state when the room stopped asking about it — so it lives here, in the room's own record, and TestADepartureAddsNothingToTheBattlesOutcomes holds battle.OutcomeCount against the number it has always had.
The two words are kept apart on purpose. A reader meeting `Outcome` twice in one file, once meaning the battle and once the match, is a reader one step from writing `battle.Outcome(result.Verdict)`.
const ( // VerdictUnfinished is a match still being played, and the zero value: a // room that has answered nothing yet has no verdict rather than a draw. VerdictUnfinished Verdict = iota // VerdictWon is a seat that took the series by the rule the room configured // — more battles than the rest of the series can still take back. VerdictWon // VerdictDrawn is every battle of the series fought with no seat ahead. It // needs no invented metric to break it: an odd series is offered precisely // so that a tie-break is never something the room has to make up, and a // series that drew every battle drew. VerdictDrawn // VerdictAbandoned is a match nobody played out, which is what a departure // leaves behind. // // ⚠️ **It is not a win, not a draw and not a forfeit.** Nobody is charged // with anything: leaving announces and nothing more, and a timeout does not // even reach here — it passes the turn and the match carries on. So Winner is // the zero Seat, Departed names who went away, and the standing is whatever // the battles already fought had made it. // // ⚠️ The concept this replaced was VerdictForfeited, with a Forfeit beside it // saying which of two routes had been taken. Both routes are gone: a // departure costs nothing (→ README.md § PvP over a LAN, where that cost is // stated) and three missed allowances cost nothing either, because a player // who walks away from the keyboard loses on the board — the opponent keeps // acting and kills the passing units — or, if both walk away, the turn cap // draws it. The forfeit was carrying nothing the board does not already // carry. // // Declared last, which is the rule this enum shares with the ones on the // wire even though nothing serialises it yet: the day it is written to a // file, appending will not reinterpret anything already written. VerdictAbandoned )