{
  "stage_01": {
    "title": "Stage 01 — Control",
    "objective": "Make the car move forward by returning an action from choose_action().",
    "explanation": "Your code controls the car directly. The choose_action(state) function is called every 100ms. Whatever string you return determines what the car does next.",
    "example": "def choose_action(state):\n    return \"ACCELERATE\"",
    "tip": "Try different actions and observe the car's behaviour. The car needs to be moving before TURN_LEFT or TURN_RIGHT have any effect.",
    "key_concept": "Code → Action → Car moves"
  },
  "stage_02": {
    "title": "Stage 02 — Observe",
    "objective": "Run the agent and watch the AI State panel update with live sensor readings.",
    "explanation": "The state dict is everything the car can 'see'. It includes speed, distances to walls, alignment with the track, and how far through the track you have progressed.",
    "example": "# Print state to understand it\ndef choose_action(state):\n    print(state)  # View in terminal\n    return \"ACCELERATE\"",
    "tip": "Watch the state values change as the car moves. Notice how left_distance and right_distance change when the car approaches a wall.",
    "key_concept": "State = what the AI can observe"
  },
  "stage_03": {
    "title": "Stage 03 — Decide",
    "objective": "Use state values to write smarter logic that keeps the car on the track.",
    "explanation": "Now you can use if/else conditions to make decisions based on what the car sees. This is rule-based driving — human-designed logic, not learning yet.",
    "example": "def choose_action(state):\n    if state[\"front_distance\"] < 30:\n        return \"BRAKE\"\n    if state[\"left_distance\"] < 15:\n        return \"TURN_RIGHT\"\n    if state[\"right_distance\"] < 15:\n        return \"TURN_LEFT\"\n    return \"ACCELERATE\"",
    "tip": "Try to reach at least one checkpoint. The car must be moving to turn effectively.",
    "key_concept": "State → Decision → Action"
  },
  "stage_04": {
    "title": "Stage 04 — Reward",
    "objective": "Open the Training Lab and observe what rewards the car receives as it drives.",
    "explanation": "Rewards are feedback signals. The system gives positive rewards for good behaviour (progress, checkpoints, finishing) and negative rewards for bad behaviour (collisions, leaving the track). The agent learns to maximise total reward.",
    "example": "Forward progress: +0.5\nReaching a checkpoint: +50\nCollision: -100\nFinishing the lap: +500",
    "tip": "Watch the reward breakdown panel as the car drives. Notice when positive and negative rewards appear.",
    "key_concept": "Reward tells the agent what is good and what is bad"
  },
  "stage_05": {
    "title": "Stage 05 — Learn",
    "objective": "Start training and watch the Q-values panel update as the agent explores the track.",
    "explanation": "Q-Learning assigns a value to every (state, action) pair. These are Q-values. When the agent takes an action and receives a reward, it updates the Q-value for that state-action pair. Over time, the Q-values represent learned knowledge: 'in this situation, this action is good/bad'.",
    "example": "Q(near_left_wall, TURN_RIGHT) = 0.83\nQ(near_left_wall, TURN_LEFT) = -0.42\n→ The agent learned: turn right when near the left wall",
    "tip": "Open the Q-Values tab and watch the numbers change as training runs. The agent starts with all zeros and discovers what works.",
    "key_concept": "Q-values = the agent's learned memory of what works"
  },
  "stage_06": {
    "title": "Stage 06 — Train",
    "objective": "Train the agent until it achieves a best reward above 50. Watch it improve.",
    "explanation": "With enough episodes, the agent learns which actions lead to better outcomes. Training runs many episodes automatically. The agent gradually shifts from exploration (trying random actions) to exploitation (using what it has learned).",
    "example": "Episode 001: Reward -82  (crashes quickly)\nEpisode 050: Reward +21  (makes it further)\nEpisode 200: Reward +134 (reaches checkpoints)\nEpisode 500: Reward +287 (completes more of track)",
    "tip": "Use the speed slider to train faster. Check the reward chart — upward trend means the agent is improving.",
    "key_concept": "More episodes = more experience = better policy"
  },
  "stage_07": {
    "title": "Stage 07 — Challenge",
    "objective": "Unlock the final challenge, run the official evaluation, and generate your result code.",
    "explanation": "The final evaluation runs your trained agent in a fixed environment with no Q-table updates. The score reflects how well your agent performs using only what it has learned. This is the test of generalisation.",
    "example": "Your agent will be evaluated on:\n• Track completion %\n• Total score\n• Completion time\n• Collisions",
    "tip": "Train as much as you want before running the evaluation. Once you generate a result code, submit it on the competition website.",
    "key_concept": "The final challenge tests what the agent actually learned"
  }
}
