= Lesson 5: Racing Rules
:lesson-id: cuttle-red-05
:agent: Red
:stage: Cuttle
:difficulty: Beginner
:duration: 30 minutes
:hidden-concept: Grammar and syntax rules

== Rules of the Race!

**Speedy Red says:** "Every race has RULES! Today we learn what moves are ALLOWED and what moves are NOT ALLOWED!"

== What You'll Learn

* What a "valid move" is
* What happens when you break the rules
* How to check if a move is okay

== The Racing Rules

=== Rule 1: Stay on the Track!

You can ONLY move on track squares. Grass is off-limits!

----
🟩🟩🟩🟩🟩
🟩⬜⬜⬜🟩   ⬜ = Track (OK!)
🟩⬜🟩⬜🟩   🟩 = Grass (NOT OK!)
🟩⬜⬜⬜🟩
🟩🟩🟩🟩🟩
----

=== Rule 2: Move One Square at a Time!

You can move: ← → ↑ ↓ (one square)

You CANNOT move: ↗ ↘ ↙ ↖ (diagonal)

=== Rule 3: No Teleporting!

You must move through EVERY square between start and finish. No skipping!

== Let's Practice!

=== Activity 1: Valid or Invalid?

Is this move allowed?

[quiz]
--
question: "Moving from A to B - is this valid?"
diagram: |
  ⬜ A ⬜
  🟩 🟩 🟩
  ⬜ B ⬜
options:
  - Valid (allowed)
  - Invalid (not allowed)
correct: Invalid (not allowed)
feedback: "Speedy Red says: 'You'd have to cross the grass! That's against the rules!'"
--

=== Activity 2: The Rule Checker

Try making moves. The Rule Checker will tell you if they're valid!

[game]
--
type: rule-checker
track: mixed-terrain
character: speedy-red
mode: validation
show-errors: true
--

**Speedy Red says:** "See the red X? That means your move breaks a rule! Try a different way!"

=== Activity 3: Fix the Invalid Path

This path has MISTAKES. Find them and fix them!

[puzzle]
--
type: path-validator
given-path:
  - [0, 0]  # START
  - [1, 0]  # OK
  - [2, 1]  # ERROR: diagonal!
  - [2, 2]  # OK
  - [3, 2]  # OK
errors-to-find: 1
--

=== Activity 4: Write a Valid Path

Now YOU write a path that follows ALL the rules!

[interactive]
--
type: path-builder
grid: 4x4
start: [0, 0]
finish: [3, 3]
obstacles: [[1, 1], [2, 0]]
rules:
  - no-diagonal
  - stay-on-track
  - no-skip
validation: real-time
--

=== Activity 5: The Rule Song

Let's remember the rules with a song!

----
🎵 Stay on the track, don't touch the green!
🎵 Move one square - not diagonal between!
🎵 No teleporting, step by step!
🎵 Follow the rules, be the best! 🎵
----

== What You Learned (Mega Secret!)

You discovered:

* **Validity:** Some moves are allowed, some aren't
* **Syntax:** Rules about what sequences are "correct"
* **Error detection:** Finding moves that break rules

**In compilers, this is called "syntax checking" - making sure code follows the rules of the language!**

== The Big Idea

Just like racing has rules about valid moves...

Programming languages have rules about valid code!

----
Valid:   print("hello")
Invalid: print"hello"(
----

The computer checks if your code follows the rules, just like we checked if race moves were valid!

== Challenge: Design Your Own Rules

Create a NEW rule for racing! Examples:

* "You can only turn right"
* "You must visit every boost"
* "No going backwards"

Then test if paths follow YOUR rule!

== Next Time

In Lesson 6, we'll combine everything - paths, obstacles, speed, AND rules - in the ULTIMATE race!

**Speedy Red says:** "Rules might seem limiting, but they make the race FAIR and FUN! Great racers know ALL the rules!"
