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 LEFTEach 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 LEFTBinary Fork
Configurable condition check:
// Example: "Is it a star?"
binaryFork.config = { property: 'shape', value: 'star' };
// true β goes RIGHT
// false β goes DOWNGrafter (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-gardenSouth
slots:
- sprout-garden-phase-4-testEast
slots:
- sprout-garden-phase-5West
slots:
- sprout-garden-phase-3