โš™๏ธ Engineering

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