Koi State Garden
The garden koi is confused! Give each pond event one clear state-change rule so the koi always knows what to do next.
π§ Before we start
In Oasis Search Party, your program remembered the next place in a queue. Today it remembers the koi's current state. An event can move the koi to a new state only when a matching rule exists. Programmers call this a state machine.
Build a state-change rule
Tap the three instruction blocks in the order a state machine checks them.
Guide three valid transitions
Watch the glowing current state. Tap the event that follows its arrow to the next state.
Protect the current state
The koi is HIDING. Pick the event with no matching arrow. A safe state machine ignores it and keeps hiding.
Debug the broken arrow
The last rule sends the koi to the wrong state. Tap the pulsing rule, then choose the correct next state.
π What you learned
- A state remembers what a program is doing now.
- An event is something the program notices.
- A transition changes the current state to a next state.
- If no transition matches, the current state stays safe and unchanged.
- Debugging repairs an arrow that points to the wrong next state.