The Warp Core Sequence
Stardate 55166.3 ยท UES Magnanimous
Briefing
The other Magnanimous has raised shields, and the Captain wants ours ready to move. The warp core has four states, cold, warming, ready and engaged, and it moves through them in that order and no other. You cannot engage a cold core. You cannot warm a core that is already engaged. And from any state whatsoever, scram takes it straight to cold, because that one is the emergency brake and it must never be refused.
Commander Raghunathan wants each transition to say whether it happened, so the bridge can tell "engaged" from "you asked to engage a cold core and nothing occurred". An invalid transition changes nothing and says so. This is a state machine, and it is the shape of half of everything you will ever build: a thing with a state, and rules about how the state may change.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขA new core is cold; warm, ready, engage step through in order
- โขSkipping ahead is refused and changes nothing
- โขGoing backwards without disengage is refused
- โขDisengage returns an engaged core to ready
- โขScram works from every state and always lands on cold
Objective
Write a class WarpCore with attribute state, one of
"cold", "warming", "ready", "engaged",
starting cold. Methods warm() (cold to warming), ready()
(warming to ready), engage() (ready to engaged), disengage()
(engaged to ready) each return True and change state only if the core is in
the right starting state, otherwise return False and change nothing.
scram() sets the state to cold from anywhere and returns True.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Keep the enum as given. Write WarpCore with WarpCore::new()
(cold), fn state(&self) -> CoreState, and methods
warm, ready, engage, disengage, each
fn(&mut self) -> bool: they change state and return
true only from the correct starting state (cold to warming, warming to
ready, ready to engaged, engaged to ready), otherwise return false and
change nothing. scram(&mut self) -> bool sets cold from anywhere and
returns true.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Store the state. Each method checks the current state, and only if the transition is allowed does it change state and return true. scram ignores the current state entirely. A match on the state per method keeps it readable.
Debrief
Cold, warming, ready. Engaged. The Captain has said "hold there", and the Maggie is holding, and across two kilometres of nothing the other ship is holding too. Chief T'Kala has moved Gerald away from the viewscreen, which she has never done before.
Deep Space is complete. Whatever happens tomorrow, the last season opens at Commander, and it is called Terminus.