lantern

sprout-garden-phase-4

Sprout Garden Phase 4: Forking

Pattern Matching and Branching - Route based on properties

Overview

Phase 4 introduces forks and grafters - plots that route sprouts based on their properties. This teaches conditional branching and path merging.

This phase teaches: Different things go different ways. Different paths can meet again.

Plot Types Introduced

Plot Symbol Category Behavior
Shape Fork ⑂● routing Routes by shape (circle/square/triangle/star)
Color Fork β‘‚πŸŽ¨ routing Routes by color (red/green/blue/yellow)
Binary Fork β‘‚? routing Routes by condition (yes/no)
Grafter βŠ• flow Combines multiple paths into one

Fork Mechanics

Shape Fork

              β”Œβ”€β”€β”€ ● circles go UP
              β”‚
    IN ───▢ [⑂●] ─── β–  squares go RIGHT
              β”‚
              └─── β–² triangles go DOWN
                   β˜… stars go LEFT

Each output direction corresponds to a shape. Sprout goes the direction matching its shape.

Color Fork

              β”Œβ”€β”€β”€ πŸ”΄ red goes UP
              β”‚
    IN ───▢ [β‘‚πŸŽ¨]─── 🟒 green goes RIGHT  
              β”‚
              └─── πŸ”΅ blue goes DOWN
                   🟑 yellow goes LEFT

Binary Fork

Configurable condition check:

// Example: "Is it a star?"
binaryFork.config = { property: 'shape', value: 'star' };

// true β†’ goes RIGHT
// false β†’ goes DOWN

Grafter (Path Merger)

The opposite of a fork - multiple paths combine:

    path A ───┐
              β”œβ”€β”€β”€β–Ά [βŠ•] ───▢ single output
    path B β”€β”€β”€β”˜

Critical concept: Order doesn't matter. First sprout to arrive goes through. Others queue (or merge if simultaneous).

Source Files (To Be Created)

File Purpose
src/plots/types/shape-fork.js 4-way shape router
src/plots/types/color-fork.js 4-way color router
src/plots/types/binary-fork.js Configurable 2-way router
src/plots/types/grafter.js Path combiner

API Documentation

files:
  - /Users/graemefawcett/working/ben.fawcett.family/activities/sprout-garden/src/plots/types/shape-fork.js
  - /Users/graemefawcett/working/ben.fawcett.family/activities/sprout-garden/src/plots/types/color-fork.js
  - /Users/graemefawcett/working/ben.fawcett.family/activities/sprout-garden/src/plots/types/binary-fork.js
  - /Users/graemefawcett/working/ben.fawcett.family/activities/sprout-garden/src/plots/types/grafter.js

❌ Fence Execution Error: "'code-api-docs' - Down the rabbit hole we went, but that node doesn't exist! Try 'oculus list' to see what's available."

Implementation Notes

Fork Implementation

// shape-fork.js
export default {
  id: 'shape-fork',
  name: 'Shape Fork',
  symbol: '⑂●',
  category: 'routing',
  phase: 4,
  
  seeds: ['left', 'right', 'up', 'down'],
  fruits: ['conditional'],  // Special marker
  
  // Return direction based on shape
  getOutputDirection(sprout) {
    const routes = {
      'circle': 'up',
      'square': 'right', 
      'triangle': 'down',
      'star': 'left'
    };
    return routes[sprout.shape] || 'right';
  },
  
  grow(sprout) {
    return sprout; // Pass through unchanged
  }
};

Simulation Changes

// In simulation.js, handle 'conditional' fruits
if (def.fruits.includes('conditional')) {
  const direction = def.getOutputDirection(sprout);
  return [direction];
}

Level Ideas

Level Challenge Teaches
24 Sort circles from squares Basic forking
25 Route by color Property checking
26 Fork then transform each path Parallel processing
27 Fork and graft back together Path merging
28 Nested forks Decision trees
29 Sort then count each type Aggregation
30 Build a sorting machine Complex routing

Pedagogy

What Kids Learn (Without Knowing It)

  • Switch statements: Different cases, different actions
  • Pattern matching: Route based on properties
  • Parallel paths: Multiple things can happen simultaneously
  • Convergence: Paths can merge back together
  • Sorting algorithms: Visual introduction to categorization

Real-World Analogies

  • Mail sorting facility (letters go to different trucks)
  • Train switching yard (cars go to different tracks)
  • Airport security (different lines for different travelers)

Verification

Live test results from [[sprout-garden-phase-4-test]]:

Test Status Details
shape-fork.js exists fail not yet implemented
color-fork.js exists fail not yet implemented
binary-fork.js exists fail not yet implemented
grafter.js exists fail not yet implemented

Slots

North

slots:
- sprout-garden
- sprout-garden

South

slots:
- sprout-garden-phase-4-test

East

slots:
- sprout-garden-phase-5

West

slots:
- sprout-garden-phase-3
↑ northsprout-garden
↓ southsprout-garden-phase-4-test
β†’ eastsprout-garden-phase-5
← westsprout-garden-phase-3