Maailmantutkija

Kasvatuskirja uteliaalle mielelle

Date: 2025-10-18

Summary

Implemented comprehensive distribution system for the Shapes Game with all 27 rules (12 existing + 15 new). Each rule now has pedagogically designed positive and negative example generators with built-in validation.

Game Structure

Input: Sequence of 4 (color, type) pairs in left-to-right order

What Was Implemented

1. Distribution Generators (shapes-distributions.js)

Created 19 distribution generator functions:

Basic Generators (1-7):

  1. uniformRandom() - 4 random (color, type) pairs
  2. allSameColor(color) - All 4 shapes same color, random types
  3. allSameType(type) - All 4 shapes same type, random colors
  4. allDifferentColors() - 4 different colors
  5. allDifferentTypes() - 4 different types
  6. exactlyKColors(k) - Exactly k distinct colors (1-4)
  7. exactlyKTypes(k) - Exactly k distinct types (1-4)

Positional Generators (8-11):

  1. firstAndLastSame(attribute) - First and last match on ‘color’ or ‘type’
  2. specificAtPosition(pos, color, type) - Specific shape at position
  3. colorPattern(pattern) - Specific color sequence (e.g., [red, blue, red, blue])
  4. typePattern(pattern) - Specific type sequence

Counting Generators (12-13):

  1. atLeastK(attribute, value, k) - At least k shapes with specific color/type
  2. exactlyK(attribute, value, k) - Exactly k shapes with specific color/type

Complexity Generators (14-19):

  1. increasingCorners() - Corner count strictly increasing
  2. nonDecreasingCorners() - Corner count non-decreasing
  3. symmetricColors() - Palindromic color sequence
  4. symmetricTypes() - Palindromic type sequence
  5. noAdjacentSameColor() - No two adjacent shapes same color
  6. noAdjacentSameType() - No two adjacent shapes same type

2. Rule Additions (shapes-rules.js)

Existing Rules (s1-s12):

New Rules (s13-s27):

3. Distribution Design Patterns

Pattern used: 20% random + 80% conceptual near-misses

Example Near-Miss Designs:

s1 (All same color):

s12 (Corners strictly increasing):

s14 (Color palindrome):

s16 (No adjacent same color):

s24 (Same color → same type):

4. Game Logic Updates (shapes-game.js)

Added methods:

  1. generateShapesForRule(shouldSatisfy)
    • Uses distribution specs from rule definitions
    • Handles different generator signatures
    • Falls back to random generation if no distribution
  2. generateShapesFallback(shouldSatisfy)
    • Fallback random generation with retry logic
    • Ensures generated shapes match desired satisfaction status

Added validation:

Corner Count System

Corner counts used for ordering rules:

This enables rules about increasing/decreasing/equal corner counts.

Logical Implication Rules

s24: “Same color → same type”

s25: “If red exists, blue exists”

Testing Checklist

Files Modified/Created

  1. /shapes/shapes-distributions.js (CREATED, 450 lines)
  2. /shapes/shapes-rules.js (UPDATED, 550 lines)
  3. /shapes/shapes-game.js (UPDATED, added validation + distributions)
  4. /shapes/SHAPES_IMPLEMENTATION.md (THIS FILE)

Design Philosophy

Pedagogical value: Near-misses help students refine understanding by testing:

Validation-first: Always validate generated examples match expected satisfaction status.

Flexibility: System gracefully falls back to random generation if distributions aren’t specified.

Next Steps

  1. Test in browser at http://localhost:4000/saannon-keksiminen.html
  2. Select “Shapes” game
  3. Play through several rules (especially new ones s13-s27)
  4. Verify:
    • Examples generate correctly
    • Validation warnings (if any) in console
    • Near-misses are pedagogically useful
    • Corner-based rules work correctly
    • Logical implication rules (s24, s25) work

Version

All files use ?v7 query parameter for cache busting.