๐Ÿ“ฆ Ops

The Shield Generator

Stardate 55143.0 ยท UES Magnanimous

Briefing

Commander Raghunathan is back, with a copy of the other ship's computer, and the first thing she wants is our own shields to work properly before anyone reads it. The shield routine has no memory: every hit is treated as the first, so the display reads "98%" after ninety hits.

Chief T'Kala wants a shield generator that knows its charge. It takes hits, which reduce it but never below zero. It recharges, but never past capacity. It reports a whole-number percentage, rounded down, and it can say plainly whether it is down. Four small behaviours, one object, and a memory.

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขA new generator starts at full charge, 100%
  • โ€ขA hit reduces the charge; two hits reduce it twice
  • โ€ขCharge never drops below zero, and is_down reports it
  • โ€ขRecharging never exceeds capacity
  • โ€ขPercent is a whole number, rounded down
Ask Commander Raghunathan for a hint

Store the capacity and the current charge as attributes. hit subtracts and clamps at 0; recharge adds and clamps at capacity; percent is charge times 100, integer-divided by capacity.