Skip to main content

State Engine & Emotions

At the core of Byte's personality is the State Engine (implemented in plain Swift), operating at a ~10Hz tick. Unlike traditional game characters that rely on rigid dispatch tables (event → animation), Byte's behavior and emotions emerge dynamically from continuously evaluating internal variables.

Core State Variables

Byte maintains six core variables (typically scored 0–100):

VariableRises fromFalls fromDrives
energyScheduled/idle sleepActive hours, interactionsWake/sleep state, animation speed
moodClicks/petting (in moderation), celebrations, noveltyProlonged neglect, over-poking, low batteryBaseline emotional tone
curiosityNovelty (new file, new app, cursor movement)Time since last novel eventWander vs. idle decision, surprise reactions
annoyanceRapid repeated clicks/drags within a short windowTime passing with no further pokingIrritated/annoyed emotion, temporary cursor-avoidance
attention_targetPointer, not decaying (set on new focus)Reset on new focusWhat the pet looks at / walks toward
routine_phaseScheduled clock (wake/work/lunch/nap/evening/sleep)Baseline bias on all other variables

Utility AI Action Scoring

Each tick, the engine evaluates candidate actions (e.g., idle, wander, sleep, greet, celebrate) using a utility AI approach.

An action's score is calculated using:

  • The base utility of the action
  • The current values of energy, mood, curiosity, annoyance, and routine_phase multiplied by specific weights
  • A small randomness/jitter factor

The action with the highest resulting score is selected for execution.

Emotion Resolution

While the state engine produces continuous numbers, the emotion layer collapses them into discrete, readable emotions every tick. This ensures the renderer always has exactly one clear expression to draw, avoiding ambiguous faces.

Emotion States

EmotionTypical TriggerExpression Cues
ContentEnergy high, mood high, curiosity/annoyance lowRelaxed eyes, slow blink, gentle idle sway
Excited / PlayfulMood high, curiosity highWide eyes, bouncy movement, quick tail/ear flick
Curious / SurprisedSudden curiosity spike (e.g., new file/app)Eyes widen briefly, head tilt toward target
SleepyEnergy low, routine phase = evening/nightSlow blink, drooping posture, yawns
AsleepEnergy very low or routine phase = sleepEyes closed, "Zzz" particle, unresponsive to minor events
Annoyedannoyance high (over-poking)Narrowed eyes, small shake, cursor-avoidance movement
Lonely / SadMood low sustained over a long neglect periodDroopy posture, slower movement, dimmer particle color
StartledVery sharp, sudden curiosity or annoyance spikeQuick jump, wide eyes, brief freeze before resuming
BoredCuriosity low sustained with no noveltySlower idle loop, occasional sigh animation

Design Constraints

  • Emotions are mutually exclusive.
  • To transition from one extreme to another (e.g., Annoyed to Excited), Byte must pass through Content for at least one tick to ensure transitions feel continuous and not glitchy.