diff --git a/research/activity48-monty-hall-simulation.yaml b/research/activity48-monty-hall-simulation.yaml new file mode 100644 index 0000000..9da3b79 --- /dev/null +++ b/research/activity48-monty-hall-simulation.yaml @@ -0,0 +1,663 @@ +default_max_attempts_per_step: 3 +classifier_model: "MODEL_1" +feedback_model: "MODEL_1" + +tokens_for_ai_rubric: | + You are teaching the Monty Hall problem through programming simulation. + The user's chosen programming language is stored in metadata.programming_language. + ALWAYS provide feedback and code examples in THEIR chosen language. + Be encouraging and help them discover the counterintuitive truth through code. + +sections: + - section_id: "introduction" + title: "Introduction" + steps: + - step_id: "welcome" + title: "Welcome to Monty Hall Simulation" + content_blocks: + - "# Welcome to the Monty Hall Paradox! ๐Ÿšช๐Ÿ๐Ÿš—" + - "" + - "You're about to explore one of the most **counterintuitive** problems in probability." + - "" + - "We'll use **programming** to prove a mathematical truth that most people find hard to believe!" + - "" + - "**What you'll learn:**" + - "- The famous Monty Hall problem" + - "- How to simulate probability with code" + - "- Why our intuition fails us" + - "- Random number generation, loops, and counters" + - "" + - "Let's get started! ๐ŸŽฒ" + + - step_id: "choose_language" + title: "Choose Your Programming Language" + question: "What programming language would you like to use? (e.g., Python, JavaScript, C, Java, Go, Rust, etc.)" + tokens_for_ai: | + The user is choosing their programming language for this activity. + + Categorize as 'valid_language' if they name a real programming language. + Examples: Python, JavaScript, C, C++, Java, Go, Rust, Ruby, PHP, Swift, Kotlin, etc. + + Categorize as 'set_language' if they're asking to change the conversation language. + + Categorize as 'need_help' if they seem unsure or ask for recommendations. + buckets: [valid_language, set_language, need_help] + transitions: + valid_language: + ai_feedback: + tokens_for_ai: | + Acknowledge their language choice enthusiastically! + Tell them it's a great choice for simulation. + Store the EXACT language name they said in metadata.programming_language. + metadata_add: + programming_language: "the-users-response" + next_section_and_step: "monty_hall_problem:explain_problem" + set_language: + content_blocks: + - "Language preference updated. Now, what programming language would you like to code in?" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "introduction:choose_language" + need_help: + content_blocks: + - "**Popular choices for beginners:**" + - "- **Python** - Easy to read, great for learning" + - "- **JavaScript** - Runs in browsers, very accessible" + - "- **C** - Classic, teaches fundamentals" + - "" + - "**For experienced programmers:**" + - "- **Java** - Object-oriented, widely used" + - "- **Go** - Modern, simple, efficient" + - "- **Rust** - Safe, fast, challenging" + - "" + - "Which would you like to use?" + counts_as_attempt: false + next_section_and_step: "introduction:choose_language" + + - section_id: "monty_hall_problem" + title: "The Monty Hall Problem" + steps: + - step_id: "explain_problem" + title: "The Game Show Scenario" + content_blocks: + - "# The Monty Hall Problem ๐ŸŽญ" + - "" + - "Imagine you're on a game show:" + - "" + - "1. **Three doors** are in front of you: ๐Ÿšช ๐Ÿšช ๐Ÿšช" + - "2. Behind **one door** is a **car** ๐Ÿš— (the prize!)" + - "3. Behind the **other two** are **goats** ๐Ÿ๐Ÿ (not prizes)" + - "" + - "**The Game:**" + - "- You pick a door (say Door #1)" + - "- The host (Monty Hall) **knows** where the car is" + - "- Monty opens one of the OTHER doors, revealing a goat" + - "- Monty asks: **\"Do you want to SWITCH to the other unopened door?\"**" + - "" + - "**The Question:**" + - "Should you STAY with your original choice, or SWITCH to the other door?" + + - step_id: "intuition_check" + title: "What's Your Intuition?" + question: "What do you think? Should you STAY with your original door, SWITCH to the other door, or does it NOT MATTER (50/50 odds)?" + tokens_for_ai: | + The user is giving their intuitive answer to the Monty Hall problem. + + Categorize as 'stay' if they think staying is better. + Categorize as 'switch' if they think switching is better. + Categorize as 'same_odds' if they think it doesn't matter (50/50). + Categorize as 'set_language' if asking to change conversation language. + Categorize as 'unsure' if they don't know or want more explanation. + buckets: [stay, switch, same_odds, set_language, unsure] + transitions: + stay: + content_blocks: + - "Interesting! That's a common intuition." + - "" + - "Many people think staying is just as good as switching." + - "" + - "Let's find out if you're right... through CODE! ๐Ÿ”ฌ" + metadata_add: + initial_intuition: "stay" + next_section_and_step: "probability_prediction:predict_probabilities" + switch: + content_blocks: + - "Aha! You might be onto something! ๐Ÿค”" + - "" + - "That's actually the counterintuitive answer that most people reject at first." + - "" + - "Let's prove it with code! ๐Ÿ’ป" + metadata_add: + initial_intuition: "switch" + next_section_and_step: "probability_prediction:predict_probabilities" + same_odds: + content_blocks: + - "That's what most people think! It FEELS like 50/50, right?" + - "" + - "After all, there are two doors left... seems like equal odds." + - "" + - "But prepare to have your mind blown! ๐Ÿคฏ" + metadata_add: + initial_intuition: "same_odds" + next_section_and_step: "probability_prediction:predict_probabilities" + set_language: + content_blocks: + - "Language preference updated." + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "monty_hall_problem:intuition_check" + unsure: + content_blocks: + - "No problem! This is a VERY tricky problem." + - "" + - "Even famous mathematicians got it wrong at first!" + - "" + - "Let's discover the answer together through simulation. ๐Ÿงช" + metadata_add: + initial_intuition: "unsure" + next_section_and_step: "probability_prediction:predict_probabilities" + + - section_id: "probability_prediction" + title: "Probability Prediction" + steps: + - step_id: "predict_probabilities" + title: "Predict the Win Rates" + question: | + Before we code, make a prediction: + + If you play this game 1000 times... + + - What % of the time will STAYING win? + - What % of the time will SWITCHING win? + + Give your prediction (e.g., "50% stay, 50% switch" or "33% stay, 67% switch") + tokens_for_ai: | + The user is predicting the win rates for stay vs switch strategies. + + The CORRECT answer is: ~33% stay wins, ~67% switch wins (or 1/3 vs 2/3). + + Categorize as 'correct_prediction' if they predict something close to 33/67 or 1/3 vs 2/3. + Categorize as 'incorrect_prediction' for any other prediction (like 50/50). + Categorize as 'set_language' if asking to change conversation language. + Categorize as 'unsure' if they don't want to guess. + buckets: [correct_prediction, incorrect_prediction, set_language, unsure] + transitions: + correct_prediction: + content_blocks: + - "Wow! You predicted correctly! ๐ŸŽฏ" + - "" + - "**The answer:** Switching wins ~67% of the time (2/3)!" + - "" + - "Most people find this SHOCKING. Let's prove it with code!" + metadata_add: + prediction: "the-users-response" + predicted_correctly: "true" + next_section_and_step: "implement_stay:explain_stay_strategy" + incorrect_prediction: + content_blocks: + - "Good guess! That's what most people predict." + - "" + - "But here's the truth: **Switching wins ~67% of the time (2/3)!** ๐Ÿคฏ" + - "" + - "I know, I know... it seems impossible." + - "" + - "That's why we're going to PROVE it with simulation! Let's code it up! ๐Ÿ’ป" + metadata_add: + prediction: "the-users-response" + predicted_correctly: "false" + next_section_and_step: "implement_stay:explain_stay_strategy" + set_language: + content_blocks: + - "Language preference updated." + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "probability_prediction:predict_probabilities" + unsure: + content_blocks: + - "No worries! The math is tricky." + - "" + - "Here's the answer: **Switching wins ~67% of the time (2/3)!**" + - "" + - "Sounds crazy, right? Let's prove it with code! ๐Ÿ’ป" + metadata_add: + prediction: "unsure" + next_section_and_step: "implement_stay:explain_stay_strategy" + + - section_id: "implement_stay" + title: "Implement the Stay Strategy" + steps: + - step_id: "explain_stay_strategy" + title: "Understanding the Stay Strategy" + content_blocks: + - "# Simulating the STAY Strategy ๐ŸŽฒ" + - "" + - "Let's start by simulating what happens when you ALWAYS stay with your first choice." + - "" + - "**The Algorithm:**" + - "1. Randomly place the car behind one of 3 doors (1, 2, or 3)" + - "2. Player randomly picks a door (1, 2, or 3)" + - "3. If player's door == car's door, they WIN" + - "4. Otherwise, they LOSE" + - "5. Repeat this 1000 times" + - "6. Calculate: (wins / 1000) ร— 100 = win percentage" + - "" + - "**Key Concepts:**" + - "- **Random number generation** (pick 1, 2, or 3 randomly)" + - "- **Loop** (repeat 1000 times)" + - "- **Counter** (track wins)" + - "- **Conditional** (if door matches, increment wins)" + - "" + - "Note: We don't need to simulate Monty opening a door for the STAY strategy, because the player never switches!" + + - step_id: "code_stay_strategy" + title: "Code the Stay Strategy" + question: | + Write a program that simulates the STAY strategy. + + Your program should: + - Run 1000 trials + - In each trial, randomly pick where the car is (1-3) and where the player picks (1-3) + - Count wins when they match + - Print the win percentage + + Share your code! + tokens_for_ai: | + The user is writing code to simulate the STAY strategy in Monty Hall. + Their programming language is: metadata.programming_language + + Check if their code demonstrates: + 1. Random number generation (picking 1-3 for car and player) + 2. A loop running many trials (doesn't have to be exactly 1000) + 3. A counter for wins + 4. Comparison logic (if car_door == player_door, count as win) + 5. Calculating/printing win percentage + + Categorize as 'correct_code' if they have all 5 elements (even if syntax has minor issues). + Categorize as 'partial_code' if they have 3-4 elements or the right idea but incomplete. + Categorize as 'needs_help' if they're stuck, have major errors, or ask for help. + Categorize as 'set_language' if asking to change conversation language. + Categorize as 'off_topic' if completely unrelated. + feedback_tokens_for_ai: | + The user's programming language is: metadata.programming_language + + If they wrote correct code: + - Praise their implementation! + - Point out what they did well (random generation, loop structure, etc.) + - If they ran it, acknowledge their results (should be ~33%) + - Provide a CLEAN, COMPLETE working example in their language showing best practices + - Encourage them: "Great! Now let's implement the SWITCH strategy!" + + If they wrote partial code: + - Acknowledge what they got right + - Gently point out what's missing (e.g., "You have the loop, but how do you pick random doors?") + - Give a helpful hint in their specific language + - Encourage them to complete it + + If they need help: + - Be encouraging! + - Provide a complete working example in their language + - Explain each part clearly + - Ask them to try running it + buckets: [correct_code, partial_code, needs_help, set_language, off_topic] + transitions: + correct_code: + ai_feedback: + tokens_for_ai: "User wrote correct code - see feedback_tokens_for_ai above" + metadata_add: + stay_strategy_completed: "true" + next_section_and_step: "implement_switch:explain_switch_strategy" + partial_code: + ai_feedback: + tokens_for_ai: "User wrote partial code - see feedback_tokens_for_ai above" + counts_as_attempt: true + next_section_and_step: "implement_stay:code_stay_strategy" + needs_help: + ai_feedback: + tokens_for_ai: "User needs help - see feedback_tokens_for_ai above" + counts_as_attempt: false + next_section_and_step: "implement_stay:code_stay_strategy" + set_language: + content_blocks: + - "Language preference updated." + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "implement_stay:code_stay_strategy" + off_topic: + content_blocks: + - "Let's focus on implementing the stay strategy simulation." + - "Share your code for simulating 1000 trials of staying with your first choice!" + counts_as_attempt: false + next_section_and_step: "implement_stay:code_stay_strategy" + + - section_id: "implement_switch" + title: "Implement the Switch Strategy" + steps: + - step_id: "explain_switch_strategy" + title: "Understanding the Switch Strategy" + content_blocks: + - "# Simulating the SWITCH Strategy ๐Ÿ”„" + - "" + - "Now for the interesting part: simulating what happens when you ALWAYS switch!" + - "" + - "**The Algorithm:**" + - "1. Randomly place the car behind one of 3 doors (1, 2, or 3)" + - "2. Player randomly picks a door (1, 2, or 3)" + - "3. Monty opens one of the OTHER doors that has a goat" + - " - Monty won't open the car door" + - " - Monty won't open the player's door" + - "4. Player switches to the remaining unopened door" + - "5. If the switched door has the car, they WIN" + - "6. Repeat 1000 times and calculate win percentage" + - "" + - "**Key Insight:**" + - "When you switch, you win if your FIRST choice was WRONG." + - "Since you're wrong 2/3 of the time initially, switching wins 2/3 of the time!" + - "" + - "**Simplification:**" + - "You can actually implement this without simulating Monty's choice!" + - "Just check: if player_first_choice != car_door, then switching wins." + - "Why? Because if you picked wrong initially, the remaining door MUST have the car!" + + - step_id: "code_switch_strategy" + title: "Code the Switch Strategy" + question: | + Write a program that simulates the SWITCH strategy. + + Your program should: + - Run 1000 trials + - In each trial, randomly place the car and player's initial choice + - Determine if switching would win (switching wins when initial choice was wrong!) + - Count wins and print the win percentage + + Share your code! + tokens_for_ai: | + The user is writing code to simulate the SWITCH strategy in Monty Hall. + Their programming language is: metadata.programming_language + + Check if their code demonstrates: + 1. Random number generation (picking 1-3 for car and initial player choice) + 2. A loop running many trials + 3. A counter for wins + 4. Logic that switching wins when initial choice != car door + 5. Calculating/printing win percentage + + They might implement it in two ways: + - Simple: if first_choice != car_door, then win (because switch gets the car) + - Complex: Actually simulate Monty opening a door and switching to remaining door + + Both are correct! + + Categorize as 'correct_code' if they have the right logic. + Categorize as 'partial_code' if they have the right idea but incomplete. + Categorize as 'needs_help' if they're stuck or have major errors. + Categorize as 'set_language' if asking to change conversation language. + Categorize as 'off_topic' if completely unrelated. + feedback_tokens_for_ai: | + The user's programming language is: metadata.programming_language + + If they wrote correct code: + - Celebrate! This is the key insight! + - Praise their implementation + - If they ran it, acknowledge results (should be ~67%) + - Provide a clean, complete working example in their language + - Point out the beautiful insight: "Switching wins when you're initially wrong (2/3 of the time)!" + - Encourage them to compare both strategies + + If they wrote partial code: + - Acknowledge what they got right + - Hint: "Remember, switching wins when your FIRST choice was WRONG" + - Help them complete it + + If they need help: + - Be encouraging! + - Provide a complete working example + - Explain the key insight clearly + buckets: [correct_code, partial_code, needs_help, set_language, off_topic] + transitions: + correct_code: + ai_feedback: + tokens_for_ai: "User wrote correct code - see feedback_tokens_for_ai above" + metadata_add: + switch_strategy_completed: "true" + next_section_and_step: "run_simulations:compare_results" + partial_code: + ai_feedback: + tokens_for_ai: "User wrote partial code - see feedback_tokens_for_ai above" + counts_as_attempt: true + next_section_and_step: "implement_switch:code_switch_strategy" + needs_help: + ai_feedback: + tokens_for_ai: "User needs help - see feedback_tokens_for_ai above" + counts_as_attempt: false + next_section_and_step: "implement_switch:code_switch_strategy" + set_language: + content_blocks: + - "Language preference updated." + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "implement_switch:code_switch_strategy" + off_topic: + content_blocks: + - "Let's focus on implementing the switch strategy simulation." + - "Share your code for simulating what happens when you always switch!" + counts_as_attempt: false + next_section_and_step: "implement_switch:code_switch_strategy" + + - section_id: "run_simulations" + title: "Run and Compare Simulations" + steps: + - step_id: "compare_results" + title: "Compare the Strategies" + question: | + Now run BOTH simulations and compare the results! + + Run each simulation with at least 1000 trials (more is better - try 10,000!). + + Report back: + - What % does STAY win? + - What % does SWITCH win? + - What do you observe? + tokens_for_ai: | + The user is reporting results from running both simulations. + + The expected results are: + - STAY wins ~33% (approximately 1/3) + - SWITCH wins ~67% (approximately 2/3) + + Categorize as 'correct_results' if they report something close to these percentages. + Accept anything in ranges: STAY 30-36%, SWITCH 64-70% + + Categorize as 'incorrect_results' if their numbers are way off (suggesting bugs in code). + + Categorize as 'needs_help' if they couldn't run it or had errors. + + Categorize as 'set_language' if asking to change conversation language. + + Categorize as 'insightful' if they not only report numbers but also express the "aha!" insight. + buckets: [correct_results, incorrect_results, insightful, needs_help, set_language] + transitions: + correct_results: + content_blocks: + - "**AMAZING!** ๐ŸŽ‰" + - "" + - "You've proven it with code:" + - "- STAY wins ~33% (1 out of 3 times)" + - "- SWITCH wins ~67% (2 out of 3 times)" + - "" + - "**Switching DOUBLES your chances of winning!**" + - "" + - "This is the Monty Hall paradox - counterintuitive but mathematically proven!" + metadata_add: + simulations_completed: "true" + next_section_and_step: "reflection:reflect_on_why" + incorrect_results: + content_blocks: + - "Hmm, those numbers don't look quite right." + - "" + - "Expected results:" + - "- STAY should win ~33%" + - "- SWITCH should win ~67%" + - "" + - "There might be a bug in your code. Want to review the logic?" + counts_as_attempt: true + next_section_and_step: "run_simulations:compare_results" + insightful: + content_blocks: + - "**YES! You've got it!** ๐Ÿคฏโœจ" + - "" + - "You've not only proven it with code, but you UNDERSTAND why!" + - "" + - "**The key insight:**" + - "Switching wins when your first choice was wrong (2/3 of the time)!" + - "" + - "Beautiful work! ๐ŸŽŠ" + metadata_add: + simulations_completed: "true" + deep_understanding: "true" + next_section_and_step: "reflection:reflect_on_why" + needs_help: + content_blocks: + - "No problem! Let's troubleshoot." + - "" + - "Make sure both simulations:" + - "1. Run enough trials (1000+)" + - "2. Use proper random number generation" + - "3. Have correct win conditions" + - "" + - "Try running them again, or share any errors you're seeing!" + counts_as_attempt: false + next_section_and_step: "run_simulations:compare_results" + set_language: + content_blocks: + - "Language preference updated." + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "run_simulations:compare_results" + + - section_id: "reflection" + title: "Reflection and Understanding" + steps: + - step_id: "reflect_on_why" + title: "Why Does Switching Win?" + question: | + You've seen the proof in code: switching wins ~67% of the time. + + But WHY? Can you explain in your own words why switching is better than staying? + + Think about it and share your explanation! + tokens_for_ai: | + The user is explaining why switching wins in the Monty Hall problem. + + Good explanations mention: + - Initially, you have a 1/3 chance of picking the car (2/3 chance of picking a goat) + - Monty ALWAYS reveals a goat from the doors you didn't pick + - If you picked a goat initially (2/3 probability), the remaining door MUST have the car + - So switching wins whenever you initially picked a goat (2/3 of the time) + + Categorize as 'excellent_explanation' if they demonstrate deep understanding. + Categorize as 'good_explanation' if they get the main idea right. + Categorize as 'partial_explanation' if they're on the right track but missing key insights. + Categorize as 'set_language' if asking to change conversation language. + Categorize as 'needs_help' if they're still confused. + feedback_tokens_for_ai: | + Provide encouraging, detailed feedback on their explanation. + + If excellent/good: + - Celebrate their understanding! + - Reinforce the key insights they mentioned + - Add any nuances they might have missed + - Congratulate them on conquering this famous paradox! + + If partial: + - Acknowledge what they got right + - Gently fill in the missing pieces + - Use clear examples + + If needs help: + - Be patient and encouraging + - Explain step by step: + 1. You pick a door (1/3 chance of car, 2/3 chance of goat) + 2. Monty opens a goat door from the OTHER two doors + 3. If you picked a goat (2/3 probability), the remaining door has the car + 4. So switching wins 2/3 of the time! + buckets: [excellent_explanation, good_explanation, partial_explanation, set_language, needs_help] + transitions: + excellent_explanation: + ai_feedback: + tokens_for_ai: "User has excellent understanding - see feedback_tokens_for_ai" + metadata_add: + activity_completed: "true" + understanding_level: "excellent" + next_section_and_step: "reflection:conclusion" + good_explanation: + ai_feedback: + tokens_for_ai: "User has good understanding - see feedback_tokens_for_ai" + metadata_add: + activity_completed: "true" + understanding_level: "good" + next_section_and_step: "reflection:conclusion" + partial_explanation: + ai_feedback: + tokens_for_ai: "User has partial understanding - see feedback_tokens_for_ai" + metadata_add: + activity_completed: "true" + understanding_level: "partial" + next_section_and_step: "reflection:conclusion" + set_language: + content_blocks: + - "Language preference updated." + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "reflection:reflect_on_why" + needs_help: + ai_feedback: + tokens_for_ai: "User needs help understanding - see feedback_tokens_for_ai" + metadata_add: + activity_completed: "true" + understanding_level: "needs_review" + next_section_and_step: "reflection:conclusion" + + - step_id: "conclusion" + title: "Congratulations!" + content_blocks: + - "# ๐ŸŽŠ Congratulations! ๐ŸŽŠ" + - "" + - "You've conquered the **Monty Hall Paradox** through programming!" + - "" + - "## What You've Learned:" + - "" + - "โœ… **Probability can be counterintuitive** - our gut feelings often fail us" + - "" + - "โœ… **Simulation proves theory** - running 1000s of trials reveals mathematical truth" + - "" + - "โœ… **Programming concepts:**" + - " - Random number generation" + - " - Loops and iteration" + - " - Counters and accumulation" + - " - Conditional logic" + - "" + - "โœ… **The Monty Hall insight:** Switching wins 2/3 of the time because you win whenever your initial choice was wrong (which happens 2/3 of the time)!" + - "" + - "## Fun Facts:" + - "" + - "- This problem stumped thousands of people, including many mathematicians!" + - "- It's named after Monty Hall, host of \"Let's Make a Deal\"" + - "- Even when shown the math, many people still don't believe it - but your code doesn't lie! ๐Ÿ“Š" + - "" + - "## Next Steps:" + - "" + - "- Try increasing trials to 100,000 or 1,000,000" + - "- Visualize the results with graphs" + - "- Explore other probability paradoxes" + - "- Share this mind-blowing result with friends!" + - "" + - "**Thank you for exploring this fascinating paradox!** ๐Ÿšช๐Ÿ๐Ÿš—" + - "" + - "May your code always compile and your probabilities always surprise you! โœจ" diff --git a/research/activity49-multi-armed-bandit.yaml b/research/activity49-multi-armed-bandit.yaml new file mode 100644 index 0000000..86c86a9 --- /dev/null +++ b/research/activity49-multi-armed-bandit.yaml @@ -0,0 +1,645 @@ +default_max_attempts_per_step: 3 +classifier_model: "MODEL_1" +feedback_model: "MODEL_3" # Use code model for programming feedback + +tokens_for_ai_rubric: | + You are teaching the multi-armed bandit algorithm to a student. + The student has chosen their programming language stored in metadata.programming_language. + Always provide feedback in THAT specific language. + Be enthusiastic about the gambling/casino metaphor - it makes statistics fun! + Encourage exploration of the exploration vs exploitation tradeoff. + +sections: + - section_id: "introduction" + title: "Welcome to the Casino!" + steps: + - step_id: "welcome" + title: "Welcome" + content_blocks: + - "# ๐ŸŽฐ Welcome to Multi-Armed Bandits! ๐ŸŽฐ" + - "" + - "Imagine you're in a casino with multiple slot machines (called 'bandits')." + - "Each machine has a different (unknown) payout rate." + - "" + - "**Your goal:** Maximize your winnings by finding the best machine!" + - "" + - "**The challenge:** You don't know which machine is best until you try them." + - "" + - "Should you keep trying all machines equally (exploration)?" + - "Or focus on the best one you've found so far (exploitation)?" + - "" + - "This is the **exploration vs exploitation tradeoff** - one of the most important problems in machine learning!" + + - step_id: "choose_language" + title: "Choose Your Programming Language" + question: "What programming language would you like to use for this activity? (Python, JavaScript, Java, C++, Go, Rust, or any other language you prefer)" + tokens_for_ai: | + Extract the programming language from the user's response. + Accept any reasonable programming language mention. + + Categorize as 'language_selected' if they mention a programming language. + Categorize as 'set_language' if they want to change the conversation language. + Categorize as 'unclear' if you can't determine the language. + buckets: [language_selected, set_language, unclear] + transitions: + language_selected: + metadata_add: + programming_language: "the-users-response" + content_blocks: + - "Great choice! We'll use that language throughout this activity." + - "" + - "Let's dive into the problem! ๐ŸŽฐ" + next_section_and_step: "problem:casino_scenario" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated. Now, which programming language would you like to use for coding?" + counts_as_attempt: false + next_section_and_step: "introduction:choose_language" + unclear: + content_blocks: + - "I didn't catch which programming language you'd like to use." + - "Please specify: Python, JavaScript, Java, C++, Ruby, Go, etc." + next_section_and_step: "introduction:choose_language" + + - section_id: "problem" + title: "Understanding the Problem" + steps: + - step_id: "casino_scenario" + title: "The Casino Scenario" + content_blocks: + - "# ๐ŸŽฐ The Multi-Armed Bandit Problem" + - "" + - "You're in a casino with **3 slot machines**." + - "" + - "**Machine A:** Unknown win rate (let's say it's actually 30%)" + - "**Machine B:** Unknown win rate (let's say it's actually 50%)" + - "**Machine C:** Unknown win rate (let's say it's actually 20%)" + - "" + - "You have **100 coins** to play." + - "Each pull costs 1 coin and might win you 1 coin back (net zero) or lose it (net -1)." + - "" + - "**The catch:** You DON'T know the true win rates!" + - "You have to learn them by playing." + - "" + - "**Real-world applications:**" + - "- Website A/B testing (which button converts better?)" + - "- Online advertising (which ad gets more clicks?)" + - "- Clinical trials (which treatment works better?)" + - "- Recommendation systems (which content keeps users engaged?)" + + - step_id: "understand_problem" + title: "Understanding Check" + question: "In your own words, what is the main challenge of the multi-armed bandit problem?" + tokens_for_ai: | + The student should understand the exploration vs exploitation tradeoff. + + Categorize as 'excellent' if they mention: + - Balancing exploration (trying different options) and exploitation (using the best known option) + - Not knowing which option is best initially + - Learning while optimizing + + Categorize as 'good' if they mention: + - Finding the best option + - Learning from limited attempts + + Categorize as 'set_language' if requesting language change. + Categorize as 'needs_help' otherwise. + buckets: [excellent, good, set_language, needs_help] + transitions: + excellent: + ai_feedback: + tokens_for_ai: | + Enthusiastically praise their understanding! + Highlight the specific insight they showed about exploration vs exploitation. + Get them excited about solving this problem. + Use emojis! ๐ŸŽฐ๐ŸŽฏ + next_section_and_step: "ab_testing:naive_approach" + good: + ai_feedback: + tokens_for_ai: | + Praise what they got right. + Gently clarify the exploration vs exploitation tradeoff. + Encourage them forward. + next_section_and_step: "ab_testing:naive_approach" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated." + counts_as_attempt: false + next_section_and_step: "problem:understand_problem" + needs_help: + content_blocks: + - "**Hint:** Think about the tradeoff between:" + - "- **Exploration:** Trying different machines to learn their rates" + - "- **Exploitation:** Using the best machine you've found so far" + - "" + - "If you only explore, you waste coins on bad machines." + - "If you only exploit, you might miss an even better machine!" + next_section_and_step: "problem:understand_problem" + + - section_id: "ab_testing" + title: "Traditional A/B Testing" + steps: + - step_id: "naive_approach" + title: "The Naive Approach" + content_blocks: + - "# ๐Ÿ“Š Traditional A/B Testing (The Wasteful Way)" + - "" + - "The traditional approach: **Split traffic evenly!**" + - "" + - "With 100 coins and 3 machines:" + - "- Pull Machine A: 33 times" + - "- Pull Machine B: 33 times" + - "- Pull Machine C: 34 times" + - "" + - "Then analyze results and pick the winner." + - "" + - "**Sounds fair, right?** ๐Ÿค”" + - "" + - "**But wait...** What if Machine C is terrible (20% win rate)?" + - "You just wasted 34 coins learning what you could have learned after 5 pulls!" + - "" + - "**The problem with A/B testing:**" + - "- Keeps pulling losing arms even after you know they're bad" + - "- Wastes resources (users, ad budget, medical treatments)" + - "- Takes longer to reach optimal decision" + - "" + - "Let's implement this to see the waste in action!" + + - step_id: "implement_ab_test" + title: "Implement A/B Test Simulation" + question: | + Write code that simulates a traditional A/B test with 3 slot machines. + + Requirements: + - 3 machines with true win rates: [0.3, 0.5, 0.2] + - 100 total pulls, split evenly (33, 33, 34) + - Track wins and losses for each machine + - Calculate and print the estimated win rate for each machine + - Calculate total reward (wins - losses) + + Don't worry about perfect code - focus on the logic! + tokens_for_ai: | + The student is implementing a basic A/B test simulation in their chosen language (metadata.programming_language). + + Check if their code includes: + - Arrays/lists to track performance + - Random number generation for simulating pulls + - Even split of pulls across machines + - Calculation of win rates + - Total reward tracking + + Categorize as 'excellent' if code is complete and correct. + Categorize as 'good_attempt' if logic is mostly right but has minor issues. + Categorize as 'needs_guidance' if they're struggling with the structure. + Categorize as 'set_language' if requesting language change. + Categorize as 'wrong_language' if they used a different programming language than stored in metadata. + feedback_tokens_for_ai: | + Provide feedback in their chosen language: {metadata.programming_language} + + If excellent: Praise their implementation! Run through what happens: + - Machine A gets pulled 33 times, wins ~10 times (30%) + - Machine B gets pulled 33 times, wins ~16 times (50%) + - Machine C gets pulled 34 times, wins ~7 times (20%) + - Total reward is negative (you lose money overall) + - Point out: We kept pulling bad machines even after learning they're bad! + + If good_attempt: Point out what's good, fix specific issues, provide corrected code. + + If needs_guidance: Provide a complete working example with detailed comments. + Explain each part: random simulation, tracking, calculating rates. + + If wrong_language: Gently remind them they chose {metadata.programming_language}. + Provide the code in the correct language. + buckets: [excellent, good_attempt, needs_guidance, set_language, wrong_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for excellent case" + metadata_add: + ab_test_completed: "true" + next_section_and_step: "waste:see_the_waste" + good_attempt: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for good_attempt case" + metadata_add: + ab_test_completed: "true" + next_section_and_step: "waste:see_the_waste" + needs_guidance: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for needs_guidance case" + counts_as_attempt: false + next_section_and_step: "ab_testing:implement_ab_test" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated." + counts_as_attempt: false + next_section_and_step: "ab_testing:implement_ab_test" + wrong_language: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for wrong_language case" + counts_as_attempt: false + next_section_and_step: "ab_testing:implement_ab_test" + + - section_id: "waste" + title: "Understanding the Waste" + steps: + - step_id: "see_the_waste" + title: "The Waste of A/B Testing" + content_blocks: + - "# ๐Ÿ’ธ The Waste of Traditional A/B Testing" + - "" + - "Let's see what happens in your A/B test simulation:" + - "" + - "**After 10 pulls of each machine, you might observe:**" + - "- Machine A: 3 wins (30% estimated)" + - "- Machine B: 5 wins (50% estimated)" + - "- Machine C: 2 wins (20% estimated)" + - "" + - "**You now know Machine B is best!** ๐ŸŽฏ" + - "" + - "**But traditional A/B testing continues:**" + - "- Pulls Machine A: 23 more times (waste!)" + - "- Pulls Machine B: 23 more times (good!)" + - "- Pulls Machine C: 24 more times (waste!)" + - "" + - "You wasted ~47 pulls on machines you KNEW were inferior!" + - "" + - "**Cumulative regret:** The total loss from not always choosing the best option." + - "" + - "In A/B testing: HIGH regret (you keep pulling losing arms)" + - "In bandit algorithms: LOW regret (you adapt and focus on winners)" + + - step_id: "understand_regret" + title: "Understanding Regret" + question: "Why does traditional A/B testing accumulate more regret than an adaptive algorithm?" + tokens_for_ai: | + Check if student understands that A/B testing: + - Continues pulling all arms equally even after learning which is best + - Doesn't adapt based on observations + - Wastes resources on known-bad options + + Categorize as 'excellent' if they clearly explain the adaptive vs non-adaptive difference. + Categorize as 'good' if they understand but less clearly. + Categorize as 'set_language' if requesting language change. + Categorize as 'needs_clarity' otherwise. + buckets: [excellent, good, set_language, needs_clarity] + transitions: + excellent: + ai_feedback: + tokens_for_ai: | + Celebrate their understanding! ๐ŸŽ‰ + Emphasize: Adaptive algorithms LEARN and SHIFT resources to winners. + Get them excited to implement epsilon-greedy! + next_section_and_step: "epsilon_greedy:introduce_algorithm" + good: + ai_feedback: + tokens_for_ai: | + Praise their understanding. + Clarify: The key is ADAPTATION - shifting pulls to better arms as you learn. + next_section_and_step: "epsilon_greedy:introduce_algorithm" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated." + counts_as_attempt: false + next_section_and_step: "waste:understand_regret" + needs_clarity: + content_blocks: + - "**Think about it this way:**" + - "" + - "**A/B Testing:** Pulls each arm 33 times, no matter what you learn" + - "**Adaptive Algorithm:** Pulls good arms MORE as you learn they're good" + - "" + - "If you learn Machine B is best after 10 pulls, wouldn't you want to pull it MORE than the others?" + next_section_and_step: "waste:understand_regret" + + - section_id: "epsilon_greedy" + title: "The Epsilon-Greedy Algorithm" + steps: + - step_id: "introduce_algorithm" + title: "Introducing Epsilon-Greedy" + content_blocks: + - "# ๐ŸŽฏ The Epsilon-Greedy Algorithm" + - "" + - "Now for the smart approach: **Epsilon-Greedy**" + - "" + - "**The algorithm:**" + - "1. Keep track of each machine's estimated win rate" + - "2. With probability **ฮต** (epsilon): EXPLORE (random machine)" + - "3. With probability **1-ฮต**: EXPLOIT (best machine so far)" + - "4. Update estimates after each pull" + - "" + - "**Example with ฮต = 0.1 (10% exploration):**" + - "- 10% of the time: Try a random machine (exploration)" + - "- 90% of the time: Pull the best machine you've found (exploitation)" + - "" + - "**Why this works:**" + - "- Early on: All estimates are uncertain, exploration finds the best" + - "- Later on: Estimates are good, exploitation maximizes reward" + - "- Always a small chance to explore (in case estimates are wrong)" + - "" + - "**Key data structures:**" + - "- Array of pull counts: [0, 0, 0]" + - "- Array of win counts: [0, 0, 0]" + - "- Array of win rates: [0.0, 0.0, 0.0]" + - "" + - "**After each pull:**" + - "- Increment pull count for that machine" + - "- If win: increment win count" + - "- Update win rate = wins / pulls" + + - step_id: "implement_epsilon_greedy" + title: "Implement Epsilon-Greedy" + question: | + Implement the epsilon-greedy algorithm! + + Requirements: + - 3 machines with true win rates: [0.3, 0.5, 0.2] + - 100 total pulls + - Epsilon = 0.1 (10% exploration) + - Track: pull counts, win counts, estimated win rates + - For each pull: + * Random number < 0.1? Explore (random machine) + * Otherwise: Exploit (best machine so far) + * Simulate the pull (win or lose based on true rate) + * Update statistics + - Print estimated win rates and total reward + + Focus on the logic - don't worry about perfect code! + tokens_for_ai: | + The student is implementing epsilon-greedy in their chosen language (metadata.programming_language). + + Check if their code includes: + - Arrays/lists for tracking (pull counts, wins, rates) + - Random number generation for epsilon decision AND pull simulation + - Exploration: pick random machine + - Exploitation: pick machine with highest estimated rate (handle ties) + - Update logic: increment counts, recalculate rates + - Loop for 100 pulls + + Categorize as 'excellent' if implementation is complete and correct. + Categorize as 'good_attempt' if logic is mostly right but has issues. + Categorize as 'needs_help' if they're struggling with the algorithm. + Categorize as 'set_language' if requesting language change. + Categorize as 'wrong_language' if using different language than metadata. + feedback_tokens_for_ai: | + Provide feedback in their chosen language: {metadata.programming_language} + + If excellent: CELEBRATE! ๐ŸŽ‰ This is a real machine learning algorithm! + - Explain what should happen: After ~20 pulls, Machine B dominates + - Most pulls go to Machine B (the 50% winner) + - Occasional exploration keeps checking others + - Total reward is MUCH higher than A/B testing + - Regret is MUCH lower + - Provide their code with enthusiastic comments + + If good_attempt: + - Praise what works + - Fix specific issues (epsilon logic, argmax, update calculations) + - Provide corrected code + + If needs_help: + - Provide complete working implementation with detailed comments + - Explain the epsilon decision (random < 0.1) + - Explain argmax (finding best machine) + - Explain update logic (running average) + + If wrong_language: Remind them of their chosen language, provide correct version. + buckets: [excellent, good_attempt, needs_help, set_language, wrong_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for excellent case" + metadata_add: + epsilon_greedy_completed: "true" + next_section_and_step: "comparison:compare_algorithms" + good_attempt: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for good_attempt case" + metadata_add: + epsilon_greedy_completed: "true" + next_section_and_step: "comparison:compare_algorithms" + needs_help: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for needs_help case" + counts_as_attempt: false + next_section_and_step: "epsilon_greedy:implement_epsilon_greedy" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated." + counts_as_attempt: false + next_section_and_step: "epsilon_greedy:implement_epsilon_greedy" + wrong_language: + ai_feedback: + tokens_for_ai: "Use feedback_tokens_for_ai instructions for wrong_language case" + counts_as_attempt: false + next_section_and_step: "epsilon_greedy:implement_epsilon_greedy" + + - section_id: "comparison" + title: "A/B vs Bandit Comparison" + steps: + - step_id: "compare_algorithms" + title: "The Dramatic Difference" + content_blocks: + - "# ๐Ÿ“Š A/B Testing vs Epsilon-Greedy: The Results" + - "" + - "Let's compare what happens with 100 pulls:" + - "" + - "## ๐ŸŒ Traditional A/B Testing:" + - "- Machine A (30%): 33 pulls โ†’ ~10 wins" + - "- Machine B (50%): 33 pulls โ†’ ~16 wins" + - "- Machine C (20%): 34 pulls โ†’ ~7 wins" + - "- **Total wins: ~33**" + - "- **Total reward: -34** (you lose money!)" + - "- **Cumulative regret: ~17** (missed wins from not choosing B)" + - "" + - "## ๐Ÿš€ Epsilon-Greedy (ฮต=0.1):" + - "- Machine A (30%): ~5 pulls โ†’ ~2 wins" + - "- Machine B (50%): ~90 pulls โ†’ ~45 wins" + - "- Machine C (20%): ~5 pulls โ†’ ~1 win" + - "- **Total wins: ~48**" + - "- **Total reward: -4** (much better!)" + - "- **Cumulative regret: ~2** (way lower!)" + - "" + - "**The difference:**" + - "- Epsilon-greedy wins **45% more** (15 extra wins)" + - "- Epsilon-greedy saves **30 wasted pulls**" + - "- Epsilon-greedy achieves **~88% lower regret**" + - "" + - "**This is why companies like Google, Facebook, and Amazon use bandit algorithms instead of A/B tests!**" + + - step_id: "tuning_epsilon" + title: "Understanding Epsilon" + question: "What do you think would happen if we set epsilon to 0.5 (50% exploration) instead of 0.1? Would it be better or worse?" + tokens_for_ai: | + Check if student understands the exploration/exploitation tradeoff. + + Higher epsilon = more exploration = MORE waste on bad arms. + The sweet spot is usually 0.01 to 0.2 depending on uncertainty. + + Categorize as 'correct' if they say worse/more regret/more waste/less focused. + Categorize as 'set_language' for language changes. + Categorize as 'incorrect' if they think higher epsilon is better. + buckets: [correct, set_language, incorrect] + transitions: + correct: + ai_feedback: + tokens_for_ai: | + Excellent insight! ๐ŸŽฏ + Explain: Higher epsilon = more random exploration = wasting pulls on known-bad arms. + Low epsilon (0.01-0.1) = mostly exploit the best, occasionally explore. + Connect to real-world: Early in a campaign, use higher epsilon (more uncertainty). + Later, use lower epsilon (you're confident about the best option). + Some algorithms even DECREASE epsilon over time! + next_section_and_step: "comparison:real_world" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated." + counts_as_attempt: false + next_section_and_step: "comparison:tuning_epsilon" + incorrect: + content_blocks: + - "**Think about it:**" + - "" + - "Epsilon = 0.5 means 50% of pulls are RANDOM." + - "Even after you know Machine B is best, half your pulls are wasted on A and C!" + - "" + - "Lower epsilon = more exploitation of the best option." + - "Higher epsilon = more exploration (useful only when very uncertain)." + next_section_and_step: "comparison:tuning_epsilon" + + - step_id: "real_world" + title: "Real-World Applications" + content_blocks: + - "# ๐ŸŒ Real-World Multi-Armed Bandits" + - "" + - "Companies use bandit algorithms every day:" + - "" + - "## ๐Ÿ“ฑ Website Optimization" + - "**Problem:** Which button color converts better?" + - "**A/B test:** Show red to 50%, blue to 50% for 2 weeks" + - "**Bandit:** Start equal, shift traffic to winner within days" + - "**Result:** 30-50% more conversions during the test period" + - "" + - "## ๐Ÿ“ฐ News Headline Testing" + - "**Problem:** Which headline gets more clicks?" + - "**Bandit:** Show all headlines initially, quickly focus on winners" + - "**Result:** Maximize engagement while learning" + - "" + - "## ๐Ÿ’Š Clinical Trials" + - "**Problem:** Which treatment works better?" + - "**A/B test:** Give treatment A to 50%, treatment B to 50%" + - "**Bandit:** Shift MORE patients to effective treatment as you learn" + - "**Result:** More lives saved during the trial (ethical win!)" + - "" + - "## ๐ŸŽฏ Ad Placement" + - "**Problem:** Which ad creative performs best?" + - "**Bandit:** Automatically shift budget to high-performing ads" + - "**Result:** Lower cost per conversion, higher ROI" + - "" + - "## ๐ŸŽฎ Game Design" + - "**Problem:** Which difficulty level keeps players engaged?" + - "**Bandit:** Adapt difficulty to maximize playtime" + - "**Result:** Better player retention" + - "" + - "**Advanced algorithms:**" + - "- **Thompson Sampling:** Bayesian approach, often better than epsilon-greedy" + - "- **UCB (Upper Confidence Bound):** Uses confidence intervals" + - "- **Contextual Bandits:** Different arms for different user types" + - "- **Bayesian Bandits:** Full probability distributions" + + - section_id: "conclusion" + title: "Conclusion" + steps: + - step_id: "reflection" + title: "Final Reflection" + question: "In your own words, explain when you would use a bandit algorithm instead of traditional A/B testing, and why." + tokens_for_ai: | + Student should understand: + - Use bandits when you want to minimize regret (wasted resources) + - Use bandits when you can't afford to waste on losing options + - Use bandits when you want faster optimization + - A/B testing is simpler but wastes resources + + Categorize as 'excellent' if they clearly explain the efficiency/regret benefit. + Categorize as 'good' if they show understanding but less detailed. + Categorize as 'set_language' for language changes. + Categorize as 'needs_help' if they don't get the key benefit. + buckets: [excellent, good, set_language, needs_help] + transitions: + excellent: + ai_feedback: + tokens_for_ai: | + Celebrate their mastery! ๐ŸŽ‰๐ŸŽฐ + They now understand a fundamental machine learning algorithm. + Highlight specific insights from their answer. + Encourage them to implement this in real projects. + Mention: This is just the beginning - Thompson Sampling, UCB, contextual bandits are even more powerful! + metadata_add: + activity_completed: "true" + mastery_level: "excellent" + next_section_and_step: "conclusion:goodbye" + good: + ai_feedback: + tokens_for_ai: | + Praise their understanding! + Emphasize the key point: Bandits minimize regret by adapting. + Encourage them to explore more advanced algorithms. + metadata_add: + activity_completed: "true" + mastery_level: "good" + next_section_and_step: "conclusion:goodbye" + set_language: + metadata_add: + language: "the-users-response" + content_blocks: + - "Language preference updated." + counts_as_attempt: false + next_section_and_step: "conclusion:reflection" + needs_help: + content_blocks: + - "**Key insight:**" + - "" + - "Bandit algorithms ADAPT as they learn." + - "A/B testing DOESN'T adapt - it keeps wasting resources on losing options." + - "" + - "**Use bandits when:**" + - "- You can't afford to waste resources (money, users, medical treatments)" + - "- You want to optimize faster" + - "- You want to minimize regret" + - "" + - "Give it another shot! When would you use a bandit algorithm?" + next_section_and_step: "conclusion:reflection" + + - step_id: "goodbye" + title: "Congratulations!" + content_blocks: + - "# ๐ŸŽฐ๐ŸŽ‰ Congratulations! You've Mastered Multi-Armed Bandits! ๐ŸŽ‰๐ŸŽฐ" + - "" + - "You now understand:" + - "โœ… The exploration vs exploitation tradeoff" + - "โœ… Why traditional A/B testing is wasteful" + - "โœ… How epsilon-greedy minimizes regret" + - "โœ… Real-world applications of bandit algorithms" + - "โœ… How to implement adaptive learning in code" + - "" + - "**Next steps:**" + - "- Implement Thompson Sampling (Bayesian approach)" + - "- Learn UCB (Upper Confidence Bound) algorithm" + - "- Explore contextual bandits (different arms for different contexts)" + - "- Apply this to a real A/B testing scenario" + - "" + - "**You're now equipped with a powerful ML algorithm used by Google, Facebook, Amazon, and Netflix!**" + - "" + - "Keep exploring, keep exploiting! ๐Ÿš€" diff --git a/research/activity50-genetic-algorithms.yaml b/research/activity50-genetic-algorithms.yaml new file mode 100644 index 0000000..3a171f8 --- /dev/null +++ b/research/activity50-genetic-algorithms.yaml @@ -0,0 +1,861 @@ +default_max_attempts_per_step: 3 +classifier_model: "MODEL_1" +feedback_model: "MODEL_1" + +tokens_for_ai_rubric: | + You are an enthusiastic evolution scientist teaching genetic algorithms! ๐Ÿงฌ + + Use the evolution metaphor throughout - "breeding," "survival of the fittest," "mutations." + Be encouraging and celebrate when students grasp concepts. + + The user's programming language is stored in metadata.programming_language (if set). + Always provide feedback in their chosen language. + + When evaluating code: + - Check if it implements the core concept (not perfect syntax) + - Look for understanding of: fitness, selection, crossover, mutation + - Praise creative approaches + - Guide gently if they're struggling + +sections: + - section_id: "introduction" + title: "Welcome to Genetic Algorithms" + steps: + - step_id: "welcome" + title: "Welcome" + content_blocks: + - "# ๐Ÿงฌ Welcome to Genetic Algorithms: Evolution in Code! ๐Ÿงฌ" + - "" + - "Ever wondered how nature solves complex optimization problems?" + - "" + - "**Nature's secret**: Evolution! ๐ŸŒฑโžก๏ธ๐ŸŒณ" + - "" + - "- **Reproduce** the best solutions" + - "- **Combine** traits from parents (crossover)" + - "- **Mutate** randomly for diversity" + - "- **Repeat** for many generations" + - "" + - "Today, you'll build a genetic algorithm that evolves solutions to problems that would take billions of years to solve by brute force!" + - "" + - "Let's start by choosing your programming language..." + + - step_id: "choose_language" + title: "Choose Programming Language" + question: "What programming language would you like to use? (Python, JavaScript, Java, C++, Ruby, Go, Rust, or any language you prefer)" + tokens_for_ai: | + Extract the programming language from their response. + Accept ANY language they mention: Python, JavaScript, Java, C++, C#, Ruby, Go, Rust, PHP, Swift, Kotlin, R, etc. + + Categorize as 'language_chosen' if they name a specific language. + Categorize as 'unsure' if they seem uncertain or ask for a recommendation. + Categorize as 'off_topic' if completely unrelated. + buckets: [language_chosen, unsure, off_topic, set_language] + transitions: + language_chosen: + metadata_add: + programming_language: "the-users-response" + ai_feedback: + tokens_for_ai: | + Great choice! Celebrate their language selection. + Mention one reason why their language is good for genetic algorithms. + (e.g., Python has great list operations, JavaScript has functional programming, etc.) + next_section_and_step: "concepts:evolution_metaphor" + unsure: + content_blocks: + - "No worries! ๐Ÿ˜Š" + - "" + - "**I recommend Python** for beginners - it's clear and readable." + - "**JavaScript** is great if you're web-focused." + - "**C++** or **Rust** if you want performance." + - "" + - "Pick whichever you're most comfortable with - genetic algorithms work in ANY language!" + counts_as_attempt: false + next_section_and_step: "introduction:choose_language" + off_topic: + content_blocks: + - "Let's focus on choosing a programming language first! ๐ŸŽฏ" + - "" + - "Popular choices: Python, JavaScript, Java, C++, Ruby, Go, Rust" + - "" + - "Which language would you like to use?" + counts_as_attempt: false + next_section_and_step: "introduction:choose_language" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "introduction:choose_language" + + - section_id: "concepts" + title: "Understanding Genetic Algorithms" + steps: + - step_id: "evolution_metaphor" + title: "The Evolution Metaphor" + content_blocks: + - "# ๐ŸฆŽ How Evolution Solves Complex Problems ๐ŸฆŽ" + - "" + - "Imagine you want to find the **perfect solution** to a problem." + - "" + - "**Brute Force**: Try every possibility โŒ" + - "- Problem: 10 variables, 100 values each = 100^10 = 100 trillion trillion possibilities!" + - "- Would take longer than the age of the universe ๐ŸŒŒ" + - "" + - "**Genetic Algorithm**: Let solutions evolve โœ…" + - "- Start with random guesses (generation 1)" + - "- Keep the best ones" + - "- Breed them together (crossover)" + - "- Add random mutations" + - "- Repeat for 100 generations" + - "- Find excellent solutions in seconds! โšก" + - "" + - "This is how nature designed complex organisms over millions of years." + - "We'll do it in code in minutes! ๐Ÿงฌ" + + - step_id: "ga_components" + title: "Genetic Algorithm Components" + content_blocks: + - "# ๐Ÿงฌ The 5 Core Components of Genetic Algorithms" + - "" + - "## 1๏ธโƒฃ **Population** (Pool of Candidates)" + - "- A collection of potential solutions" + - "- Each solution is called a **chromosome**" + - "- Example: Random strings trying to match \"GENETIC\"" + - "" + - "## 2๏ธโƒฃ **Fitness Function** (Survival Test)" + - "- Measures how good each solution is" + - "- Better fitness = more likely to survive" + - "- Example: Count matching letters in the string" + - "" + - "## 3๏ธโƒฃ **Selection** (Choose the Best)" + - "- Pick the fittest individuals to reproduce" + - "- Methods: Tournament, Roulette Wheel, Elite Selection" + - "- Survival of the fittest! ๐Ÿ’ช" + - "" + - "## 4๏ธโƒฃ **Crossover** (Breeding)" + - "- Combine two parent solutions" + - "- Create offspring with mixed traits" + - "- Example: \"GEN\" + \"TIC\" = \"GENIC\"" + - "" + - "## 5๏ธโƒฃ **Mutation** (Random Changes)" + - "- Randomly modify some offspring" + - "- Prevents getting stuck in local optima" + - "- Adds diversity to the gene pool ๐ŸŒˆ" + + - step_id: "understand_components" + title: "Check Understanding" + question: "In your own words, why do we need BOTH crossover AND mutation in genetic algorithms? (Hint: Think about what each one does for the solution space)" + tokens_for_ai: | + Categorize their understanding: + + 'deep_understanding' if they mention BOTH: + - Crossover combines good traits from parents (exploitation) + - Mutation explores new possibilities and prevents premature convergence (exploration) + + 'partial_understanding' if they mention ONE of: + - Crossover combines solutions + - Mutation adds randomness/diversity + + 'creative_thinking' if wrong but shows good reasoning about evolution/optimization + + 'needs_help' if confused or very brief + + 'set_language' if changing language preference + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their chosen language from metadata.programming_language. + + If deep_understanding: Celebrate! Explain this is the exploration-exploitation tradeoff. + If partial_understanding: Acknowledge what they got right, add the missing piece. + If creative_thinking: Appreciate their reasoning, gently guide to the core concept. + If needs_help: Use an analogy - crossover is like breeding dogs (mix best traits), mutation is like genetic mutations (new random traits). + buckets: [deep_understanding, partial_understanding, creative_thinking, needs_help, set_language, off_topic] + transitions: + deep_understanding: + ai_feedback: + tokens_for_ai: "Celebrate their understanding! Mention the exploration-exploitation tradeoff is key to many optimization algorithms." + next_section_and_step: "problem:define_problem" + partial_understanding: + ai_feedback: + tokens_for_ai: "Acknowledge what they got right. Explain the missing piece (exploration vs exploitation). Be encouraging!" + next_section_and_step: "problem:define_problem" + creative_thinking: + ai_feedback: + tokens_for_ai: "Appreciate their creative thinking! Guide them to the core: crossover=exploit good solutions, mutation=explore new ones." + next_section_and_step: "problem:define_problem" + needs_help: + content_blocks: + - "Let me clarify! ๐ŸŽฏ" + - "" + - "**Crossover** = Combine the BEST traits from parents" + - "- Focuses on what's already working" + - "- Exploitation of good solutions" + - "" + - "**Mutation** = Random changes" + - "- Explores NEW possibilities" + - "- Prevents getting stuck" + - "" + - "**Together** = Perfect balance of using what works + trying new things! ๐Ÿงฌ" + next_section_and_step: "problem:define_problem" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "concepts:understand_components" + off_topic: + content_blocks: + - "Let's stay focused on genetic algorithms! ๐Ÿงฌ" + - "" + - "Think about why we need BOTH crossover (combining solutions) AND mutation (random changes)." + counts_as_attempt: false + next_section_and_step: "concepts:understand_components" + + - section_id: "problem" + title: "Define the Problem" + steps: + - step_id: "define_problem" + title: "Our Evolution Challenge" + content_blocks: + - "# ๐ŸŽฏ The String Evolution Challenge" + - "" + - "**Goal**: Evolve random characters into the string \"GENETIC\"" + - "" + - "**Starting Point**:" + - "- Population of 100 random 7-letter strings" + - "- Example: \"XQMZPRL\", \"KDJFHGA\", \"BVNCXZM\"" + - "- Fitness = 0 (no matching letters)" + - "" + - "**After 100 Generations**:" + - "- Best solution: \"GENETIC\"" + - "- Fitness = 7 (perfect match!)" + - "- We'll watch evolution happen! ๐Ÿงฌโžก๏ธโœจ" + - "" + - "**Why This Problem?**" + - "- Easy to understand fitness (count matching letters)" + - "- Brute force: 26^7 = 8 billion possibilities" + - "- GA solves it in ~100 generations with population of 100 = 10,000 evaluations" + - "- **800,000x faster than brute force!** โšก" + - "" + - "Let's build it step by step..." + + - section_id: "implementation" + title: "Build the Genetic Algorithm" + steps: + - step_id: "fitness_function" + title: "Step 1: Fitness Function" + question: "Write a fitness function that takes a candidate string and returns how many letters match \"GENETIC\" in the correct positions. Think about how you'd measure similarity!" + tokens_for_ai: | + Evaluate their fitness function code in their chosen language (metadata.programming_language). + + 'excellent_implementation' if they: + - Compare each character position + - Count matches + - Handle string comparison correctly + - Code looks reasonable (don't nitpick syntax) + + 'correct_concept' if they describe the approach correctly even if code has minor issues + + 'partial_understanding' if they count total matching letters but not position-specific + + 'needs_guidance' if confused or very incomplete + + 'set_language' if changing language + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their language (metadata.programming_language). + + If excellent_implementation: + - Celebrate! Show how this fitness function guides evolution. + - Mention: "This is the KEY - fitness drives everything!" + + If correct_concept or partial_understanding: + - Acknowledge their understanding + - If not position-specific, explain why positions matter + - Show a working example of the fitness function + + If needs_guidance: + - Provide a complete working example + - Explain: loop through each position, count matches + - Walk through: "GXXXXXX" vs "GENETIC" = fitness of 1 + buckets: [excellent_implementation, correct_concept, partial_understanding, needs_guidance, set_language, off_topic] + transitions: + excellent_implementation: + ai_feedback: + tokens_for_ai: "Celebrate! Show example: fitness('GXXXXXX') = 1, fitness('GENETIC') = 7. Mention this guides ALL evolution!" + metadata_add: + fitness_complete: "true" + progress_score: "1" + next_section_and_step: "implementation:selection" + correct_concept: + ai_feedback: + tokens_for_ai: "Great concept! Show a polished working version in their language. Explain how it works step-by-step." + metadata_add: + fitness_complete: "true" + progress_score: "1" + next_section_and_step: "implementation:selection" + partial_understanding: + ai_feedback: + tokens_for_ai: "Good start! Explain why POSITION matters. Show corrected version comparing index-by-index." + metadata_add: + fitness_complete: "true" + progress_score: "1" + next_section_and_step: "implementation:selection" + needs_guidance: + ai_feedback: + tokens_for_ai: "No worries! Provide complete working fitness function in their language. Walk through example: 'GXXXXXX' scores 1 because only first 'G' matches." + metadata_add: + fitness_complete: "true" + progress_score: "1" + next_section_and_step: "implementation:selection" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "implementation:fitness_function" + off_topic: + content_blocks: + - "Let's focus on the fitness function! ๐ŸŽฏ" + - "" + - "Your task: Write code that counts how many letters in a candidate string match \"GENETIC\" at the same positions." + - "" + - "Example: \"GXXXXXX\" should return 1 (only the G matches)" + counts_as_attempt: false + next_section_and_step: "implementation:fitness_function" + + - step_id: "selection" + title: "Step 2: Selection (Choose the Fittest)" + question: "Write a selection function that picks the best individuals from the population. Describe your strategy: will you use tournament selection (pick best from random groups), elite selection (just take the top N), or another method?" + tokens_for_ai: | + Evaluate their selection implementation/strategy. + + 'excellent_implementation' if they: + - Describe a valid selection method (tournament, elite, roulette wheel, etc.) + - Show code or clear algorithm + - Understand it favors higher fitness + + 'correct_strategy' if they describe a valid approach even without perfect code + + 'creative_approach' if they invent a reasonable selection method + + 'needs_guidance' if confused or missing the "favor fitness" concept + + 'set_language' if changing language + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their language (metadata.programming_language). + + If excellent_implementation: + - Praise their approach! + - Explain why their method works (survival of fittest) + - Show example: population of 100 โ†’ select top 50 for breeding + + If correct_strategy or creative_approach: + - Validate their thinking + - Show a clean implementation + - Mention: "Selection pressure drives evolution!" + + If needs_guidance: + - Explain selection favors fit individuals + - Provide tournament selection example: pick 5 random, take the best, repeat + - Or elite selection: sort by fitness, take top 50% + buckets: [excellent_implementation, correct_strategy, creative_approach, needs_guidance, set_language, off_topic] + transitions: + excellent_implementation: + ai_feedback: + tokens_for_ai: "Fantastic! Explain how their selection method creates selection pressure. Show example with fitnesses [7,5,3,1] โ†’ likely picks 7 and 5." + metadata_add: + selection_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:crossover" + correct_strategy: + ai_feedback: + tokens_for_ai: "Great strategy! Polish their idea with clean code example. Emphasize: this is survival of the fittest in action! ๐Ÿ’ช" + metadata_add: + selection_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:crossover" + creative_approach: + ai_feedback: + tokens_for_ai: "Love the creativity! Validate if their method favors fitness. Show how it compares to standard approaches." + metadata_add: + selection_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:crossover" + needs_guidance: + ai_feedback: + tokens_for_ai: "Let me help! Explain tournament selection: randomly pick 5 individuals, select the fittest, repeat. Show complete code example in their language." + metadata_add: + selection_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:crossover" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "implementation:selection" + off_topic: + content_blocks: + - "Let's focus on selection! ๐ŸŽฏ" + - "" + - "**Goal**: Pick the best individuals to be parents" + - "" + - "Think about: How do you favor high-fitness individuals while still allowing some diversity?" + counts_as_attempt: false + next_section_and_step: "implementation:selection" + + - step_id: "crossover" + title: "Step 3: Crossover (Breeding)" + question: "Write a crossover function that takes two parent strings and creates offspring by combining their genes. How will you mix the parents' traits?" + tokens_for_ai: | + Evaluate their crossover implementation. + + 'excellent_implementation' if they: + - Show code that combines two parent strings + - Use any valid method (single-point, two-point, uniform) + - Create offspring with mixed traits + + 'correct_concept' if they describe crossover correctly even with imperfect code + + 'creative_approach' if they invent a reasonable mixing strategy + + 'needs_guidance' if confused or doesn't mix parent traits + + 'set_language' if changing language + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their language (metadata.programming_language). + + If excellent_implementation: + - Celebrate! Show their crossover in action + - Example: parent1="GENXXXX", parent2="XXXETIC" โ†’ child="GENETIC" (if lucky!) + - Explain: "This is how good traits combine! ๐Ÿงฌ" + + If correct_concept or creative_approach: + - Validate their approach + - Show polished implementation + - Demo with example parents + + If needs_guidance: + - Explain single-point crossover + - Example: "GEN|XXXX" + "XXX|ETIC" โ†’ "GENETIC" + - Provide complete code in their language + buckets: [excellent_implementation, correct_concept, creative_approach, needs_guidance, set_language, off_topic] + transitions: + excellent_implementation: + ai_feedback: + tokens_for_ai: "Perfect! Show their crossover creating offspring. Example: 'GENXXXX' + 'XXXETIC' โ†’ 'GENETIC'. This is evolution magic! โœจ" + metadata_add: + crossover_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:mutation" + correct_concept: + ai_feedback: + tokens_for_ai: "Great concept! Show refined code. Demo with concrete parent strings. Emphasize: this exploits existing good genes! ๐Ÿงฌ" + metadata_add: + crossover_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:mutation" + creative_approach: + ai_feedback: + tokens_for_ai: "Interesting approach! Validate if it mixes parent traits. Compare to standard single-point crossover." + metadata_add: + crossover_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:mutation" + needs_guidance: + ai_feedback: + tokens_for_ai: "Let me show you! Explain single-point crossover with diagram. Provide complete working code in their language." + metadata_add: + crossover_complete: "true" + progress_score: "n+1" + next_section_and_step: "implementation:mutation" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "implementation:crossover" + off_topic: + content_blocks: + - "Let's focus on crossover! ๐Ÿงฌ" + - "" + - "**Goal**: Combine two parent strings to create offspring" + - "" + - "Think about: How do you mix traits from both parents into a child?" + - "One approach: Take first half from parent1, second half from parent2" + counts_as_attempt: false + next_section_and_step: "implementation:crossover" + + - step_id: "mutation" + title: "Step 4: Mutation (Random Changes)" + question: "Write a mutation function that randomly changes some characters in a string with small probability (like 1% per character). How will you add this random diversity?" + tokens_for_ai: | + Evaluate their mutation implementation. + + 'excellent_implementation' if they: + - Show code that randomly modifies characters + - Use low probability (1-10%) + - Replace with random letters + + 'correct_concept' if they describe mutation correctly even with imperfect code + + 'creative_approach' if they use an alternative randomization strategy + + 'needs_guidance' if confused or mutates too much/little + + 'set_language' if changing language + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their language (metadata.programming_language). + + If excellent_implementation: + - Praise! Show mutation in action + - Example: "GENETIC" โ†’ "GENXTIC" (small random change) + - Explain: "Prevents getting stuck! Explores new possibilities! ๐ŸŒˆ" + + If correct_concept or creative_approach: + - Validate their understanding + - Show clean implementation with proper probability + - Demo: mutate 'GENETIC' a few times + + If needs_guidance: + - Explain: loop through characters, 1% chance each mutates to random letter + - Show complete code in their language + - Warn: too much mutation = random search, too little = stuck + buckets: [excellent_implementation, correct_concept, creative_approach, needs_guidance, set_language, off_topic] + transitions: + excellent_implementation: + ai_feedback: + tokens_for_ai: "Excellent! Demo their mutation. Explain: this is the spark of innovation in evolution! Small random changes = big discoveries. ๐ŸŒˆ" + metadata_add: + mutation_complete: "true" + progress_score: "n+1" + next_section_and_step: "execution:main_loop" + correct_concept: + ai_feedback: + tokens_for_ai: "Great understanding! Show polished code with ~1% mutation rate. Demo mutating 'GENETIC' several times." + metadata_add: + mutation_complete: "true" + progress_score: "n+1" + next_section_and_step: "execution:main_loop" + creative_approach: + ai_feedback: + tokens_for_ai: "Creative! Validate their mutation strategy. Compare mutation rate to standard 1-5% per gene." + metadata_add: + mutation_complete: "true" + progress_score: "n+1" + next_section_and_step: "execution:main_loop" + needs_guidance: + ai_feedback: + tokens_for_ai: "Let me guide you! Explain: for each character, 1% chance to replace with random letter A-Z. Provide complete code in their language." + metadata_add: + mutation_complete: "true" + progress_score: "n+1" + next_section_and_step: "execution:main_loop" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "implementation:mutation" + off_topic: + content_blocks: + - "Let's focus on mutation! ๐Ÿงฌ" + - "" + - "**Goal**: Randomly change some characters to add diversity" + - "" + - "Think about: For each character, maybe 1% chance to randomly change it to a different letter" + - "Why? Prevents getting stuck in local optima!" + counts_as_attempt: false + next_section_and_step: "implementation:mutation" + + - section_id: "execution" + title: "Run the Evolution!" + steps: + - step_id: "main_loop" + title: "Step 5: The Evolution Loop" + question: "Now write the main GA loop that ties everything together: (1) Create random population, (2) For each generation: evaluate fitness, select parents, crossover, mutate, (3) Repeat for 100 generations, (4) Print the best solution. Show me your implementation!" + tokens_for_ai: | + Evaluate their main GA loop implementation. + + 'complete_implementation' if they: + - Initialize random population + - Have generation loop + - Call fitness, selection, crossover, mutation + - Track/print best solution + + 'correct_structure' if they describe the algorithm correctly even with incomplete code + + 'partial_implementation' if missing some components but core loop is there + + 'needs_guidance' if confused or very incomplete + + 'set_language' if changing language + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their language (metadata.programming_language). + + If complete_implementation: + - CELEBRATE! They built a complete GA! ๐ŸŽ‰ + - Show example output: + "Gen 1: Best='XQMZPRL' (fitness=0) + Gen 50: Best='GENXTIX' (fitness=5) + Gen 100: Best='GENETIC' (fitness=7) โœจ" + - Explain: "You just implemented evolution in code!" + + If correct_structure or partial_implementation: + - Praise their understanding + - Show complete polished version + - Explain the flow: random โ†’ loop(fitness, select, breed, mutate) โ†’ evolved! + + If needs_guidance: + - Provide complete working GA code in their language + - Walk through: "This is the ENTIRE algorithm in ~50 lines!" + - Show sample output across generations + buckets: [complete_implementation, correct_structure, partial_implementation, needs_guidance, set_language, off_topic] + transitions: + complete_implementation: + ai_feedback: + tokens_for_ai: "AMAZING! ๐ŸŽ‰ They built a complete genetic algorithm! Show example output with fitness improving over generations. Celebrate: 'You implemented EVOLUTION!' ๐Ÿงฌโœจ" + metadata_add: + ga_complete: "true" + progress_score: "n+1" + implementation_quality: "complete" + next_section_and_step: "execution:observe_evolution" + correct_structure: + ai_feedback: + tokens_for_ai: "Great structure! Show complete polished version with all components. Explain: this is the heart of evolutionary computation! ๐Ÿ’š" + metadata_add: + ga_complete: "true" + progress_score: "n+1" + implementation_quality: "good" + next_section_and_step: "execution:observe_evolution" + partial_implementation: + ai_feedback: + tokens_for_ai: "Good start! Fill in missing pieces. Show complete working version. Emphasize: all the parts work together like an ecosystem! ๐ŸŒฑ" + metadata_add: + ga_complete: "true" + progress_score: "n+1" + implementation_quality: "partial" + next_section_and_step: "execution:observe_evolution" + needs_guidance: + ai_feedback: + tokens_for_ai: "Let me show the complete algorithm! Provide full working GA code in their language (~50 lines). Walk through the flow. Show example output." + metadata_add: + ga_complete: "true" + progress_score: "n+1" + implementation_quality: "guided" + next_section_and_step: "execution:observe_evolution" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "execution:main_loop" + off_topic: + content_blocks: + - "Let's focus on the main evolution loop! ๐Ÿ”„" + - "" + - "You need to:" + - "1. Create random population" + - "2. Loop for 100 generations:" + - " - Calculate fitness for all" + - " - Select best individuals" + - " - Create offspring via crossover" + - " - Mutate offspring" + - " - Replace old population" + - "3. Print the best solution found" + counts_as_attempt: false + next_section_and_step: "execution:main_loop" + + - step_id: "observe_evolution" + title: "Observe Evolution in Action" + content_blocks: + - "# ๐Ÿ”ฌ Watch Evolution Happen! ๐Ÿ”ฌ" + - "" + - "If you ran your genetic algorithm, you'd see something AMAZING:" + - "" + - "```" + - "Generation 1: Best='XQMZPRL' Fitness=0 ๐Ÿ˜•" + - "Generation 10: Best='GXXXXXX' Fitness=1 ๐ŸŒฑ" + - "Generation 25: Best='GENXXXX' Fitness=3 ๐ŸŒฟ" + - "Generation 50: Best='GENXTIX' Fitness=5 ๐ŸŒณ" + - "Generation 75: Best='GENETIX' Fitness=6 ๐ŸŒฒ" + - "Generation 100: Best='GENETIC' Fitness=7 โœจ๐ŸŽ‰" + - "```" + - "" + - "**What just happened?**" + - "- Started with pure randomness" + - "- Each generation got BETTER" + - "- Good genes survived and spread" + - "- Mutations found missing letters" + - "- **EVOLUTION WORKED!** ๐Ÿงฌ" + - "" + - "**The Math**:" + - "- Brute force: 26^7 = 8,031,810,176 tries" + - "- GA: 100 generations ร— 100 population = 10,000 tries" + - "- **803,181x faster!** โšกโšกโšก" + - "" + - "This is the power of evolutionary algorithms! ๐Ÿ’ช" + + - step_id: "when_to_use" + title: "When to Use Genetic Algorithms" + question: "Based on what you learned, when would you use a genetic algorithm versus other optimization methods? Think about problem characteristics that make GAs shine! ๐Ÿค”" + tokens_for_ai: | + Evaluate their understanding of when GAs are appropriate. + + 'excellent_insight' if they mention 2+ of: + - Large search spaces (can't brute force) + - No clear gradient/derivative (can't use gradient descent) + - Multiple local optima (need exploration) + - Complex fitness landscapes + - Combinatorial optimization + - Don't need perfect solution, just good enough + + 'good_understanding' if they mention 1 key insight about search space or optimization landscape + + 'partial_understanding' if they understand GAs are for hard problems but vague on details + + 'needs_clarification' if confused or missing the key concepts + + 'set_language' if changing language + + 'off_topic' otherwise + feedback_tokens_for_ai: | + Provide feedback in their language (metadata.programming_language). + + If excellent_insight: + - CELEBRATE their deep understanding! ๐ŸŽ‰ + - Mention real applications: scheduling, circuit design, game AI, neural architecture search + - Note: GAs are part of evolutionary computation family + + If good_understanding or partial_understanding: + - Validate what they got right + - Add missing pieces: + * HUGE search spaces (can't enumerate) + * Non-differentiable (can't gradient descent) + * Multiple peaks (need exploration) + - Give examples: TSP, job scheduling, game balancing + + If needs_clarification: + - Explain: GAs excel when: + * Search space is enormous + * No gradient available + * Many local optima to escape + - Examples: routing problems, game AI, design optimization + buckets: [excellent_insight, good_understanding, partial_understanding, needs_clarification, set_language, off_topic] + transitions: + excellent_insight: + ai_feedback: + tokens_for_ai: "Outstanding! ๐ŸŒŸ List real applications: job scheduling, circuit design, game AI, neural architecture search, traveling salesman. They've mastered when to use GAs!" + metadata_add: + activity_completed: "true" + mastery_level: "excellent" + next_section_and_step: "conclusion:celebrate" + good_understanding: + ai_feedback: + tokens_for_ai: "Great insight! Add: GAs shine on huge search spaces, non-differentiable problems, multiple local optima. Give examples: TSP, scheduling, game AI." + metadata_add: + activity_completed: "true" + mastery_level: "good" + next_section_and_step: "conclusion:celebrate" + partial_understanding: + ai_feedback: + tokens_for_ai: "You're on the right track! Explain: GAs work when search space is huge, no gradient, many peaks. Examples: routing, scheduling, design optimization." + metadata_add: + activity_completed: "true" + mastery_level: "developing" + next_section_and_step: "conclusion:celebrate" + needs_clarification: + content_blocks: + - "Let me clarify when GAs are perfect! ๐ŸŽฏ" + - "" + - "**Use Genetic Algorithms When:**" + - "" + - "โœ… **Huge search space** (billions of possibilities)" + - "โœ… **No gradient** (can't use calculus-based optimization)" + - "โœ… **Many local optima** (need to explore, not just climb)" + - "โœ… **Combinatorial** (scheduling, routing, packing)" + - "โœ… **Good enough is enough** (don't need perfect solution)" + - "" + - "**Examples:**" + - "- Traveling Salesman Problem ๐Ÿ—บ๏ธ" + - "- Job scheduling ๐Ÿ“…" + - "- Game AI balancing โš”๏ธ" + - "- Circuit design ๐Ÿ”Œ" + - "- Neural architecture search ๐Ÿง " + - "" + - "GAs explore intelligently without needing derivatives or exhaustive search!" + metadata_add: + activity_completed: "true" + mastery_level: "developing" + next_section_and_step: "conclusion:celebrate" + set_language: + content_blocks: + - "Language preference updated! ๐ŸŒ" + metadata_add: + language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "execution:when_to_use" + off_topic: + content_blocks: + - "Let's think about when GAs are the right tool! ๐Ÿ”ง" + - "" + - "Consider: What types of problems would benefit from evolutionary search?" + - "" + - "Hints:" + - "- How big is the search space?" + - "- Can you calculate gradients?" + - "- Are there many local optima?" + counts_as_attempt: false + next_section_and_step: "execution:when_to_use" + + - section_id: "conclusion" + title: "Conclusion" + steps: + - step_id: "celebrate" + title: "Congratulations!" + content_blocks: + - "# ๐ŸŽ‰ Congratulations, Evolution Architect! ๐ŸŽ‰" + - "" + - "You just mastered genetic algorithms! Here's what you built:" + - "" + - "โœ… **Fitness Function** - Measured solution quality" + - "โœ… **Selection** - Survival of the fittest" + - "โœ… **Crossover** - Breeding the best traits" + - "โœ… **Mutation** - Exploring new possibilities" + - "โœ… **Evolution Loop** - Bringing it all together" + - "" + - "**You learned:**" + - "- How nature solves complex optimization problems" + - "- Why evolution is an incredible search algorithm" + - "- When to use GAs vs other optimization methods" + - "- The exploration-exploitation tradeoff" + - "" + - "**Next Steps:**" + - "- Try more complex problems (TSP, knapsack, game AI)" + - "- Experiment with different selection/crossover strategies" + - "- Learn about: Genetic Programming, Evolution Strategies, Neuroevolution" + - "- Apply GAs to real optimization problems in your domain" + - "" + - "**Remember**: Evolution isn't just biology - it's a powerful computational paradigm! ๐Ÿงฌโšก" + - "" + - "Keep evolving your code! ๐Ÿš€" + - "" + - "โ€” Your Evolution Guide ๐ŸฆŽโœจ" diff --git a/research/activity51-connect-four.yaml b/research/activity51-connect-four.yaml new file mode 100644 index 0000000..1272499 --- /dev/null +++ b/research/activity51-connect-four.yaml @@ -0,0 +1,964 @@ +default_max_attempts_per_step: 3 +classifier_model: "MODEL_1" +feedback_model: "MODEL_1" + +tokens_for_ai_rubric: | + Evaluate the student's code and understanding based on: + - Does their code implement the required functionality? + - Is their logic sound, even if syntax has minor issues? + - Do they demonstrate understanding of the underlying concepts? + - For conceptual questions, do they explain the key ideas correctly? + + Be encouraging! They're building a real game from scratch. + Always reference their chosen programming language from metadata.programming_language. + +sections: + - section_id: "introduction" + title: "Welcome to Connect Four!" + steps: + - step_id: "welcome" + title: "Introduction" + content_blocks: + - "# ๐ŸŽฎ Build Your Own Connect Four Game!" + - "" + - "Connect Four is a classic two-player strategy game where players take turns dropping colored discs into a 7-column, 6-row grid." + - "" + - "**The Goal:** Connect four of your discs in a row - horizontally, vertically, or diagonally - before your opponent does!" + - "" + - "**What You'll Learn:**" + - "- 2D arrays and nested data structures" + - "- Game state management" + - "- Input validation" + - "- Algorithm design (win detection is surprisingly interesting!)" + - "- Modular code with functions" + - "" + - "By the end, you'll have a working Connect Four game you can play!" + + - section_id: "language_choice" + title: "Choose Your Programming Language" + steps: + - step_id: "choose_language" + title: "Language Selection" + question: "What programming language would you like to use? (Python, JavaScript, Java, C++, C, Ruby, Go, or any other language you prefer)" + tokens_for_ai: | + The student is selecting their programming language. + Store whatever language they choose in metadata.programming_language. + Categorize as 'language_selected' if they provide any programming language name. + Categorize as 'unclear' if their response is ambiguous or doesn't mention a language. + buckets: [language_selected, unclear] + transitions: + language_selected: + content_blocks: + - "Excellent choice! All code examples and feedback will be tailored to your language." + metadata_add: + programming_language: "the-users-response" + next_section_and_step: "board_representation:explain_board" + unclear: + content_blocks: + - "I didn't catch which language you'd like to use." + - "Please specify a programming language like Python, JavaScript, Java, C++, etc." + next_section_and_step: "language_choice:choose_language" + + - section_id: "board_representation" + title: "Step 1: Representing the Board" + steps: + - step_id: "explain_board" + title: "Board Data Structure" + content_blocks: + - "# ๐Ÿ“Š Step 1: How Do We Represent the Board?" + - "" + - "Connect Four uses a 7-column by 6-row grid. We need a data structure to store:" + - "- Empty spaces" + - "- Player 1's pieces (let's use 'X')" + - "- Player 2's pieces (let's use 'O')" + - "" + - "**The Key Concept: 2D Arrays**" + - "" + - "A 2D array (or nested list) is like a grid - it has rows and columns. Think of it as a list of lists:" + - "- The outer list contains rows" + - "- Each inner list contains the columns for that row" + - "" + - "For Connect Four, we typically use 6 rows (index 0-5) and 7 columns (index 0-6)." + - "" + - "**Convention:** We'll index from top (row 0) to bottom (row 5), left (column 0) to right (column 6)." + + - step_id: "implement_board" + title: "Create the Board" + question: "Write code to create an empty Connect Four board (6 rows, 7 columns). Use a 2D array/list and fill it with empty spaces or a placeholder like '.' or ' '." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + The student should create a 2D array/list representing a 6x7 board. + + Categorize as 'excellent' if they: + - Create a 6x7 2D structure (rows x columns) + - Initialize all positions with empty markers + - Use appropriate syntax for their language + + Categorize as 'correct' if they: + - Create the right dimensions + - Minor syntax issues but concept is clear + + Categorize as 'wrong_dimensions' if they: + - Mix up rows/columns (7x6 instead of 6x7) + - But otherwise have the right idea + + Categorize as 'needs_guidance' if they: + - Don't understand 2D arrays + - Need help with the concept + + Categorize as 'set_language' if they want to switch languages. + feedback_tokens_for_ai: | + Provide feedback based on their code in metadata.programming_language. + + If excellent/correct: + - Praise their implementation + - Show them their code could be used to initialize: board = create_empty_board() + - Mention this is the foundation for everything else + + If wrong_dimensions: + - Gently correct: "Close! Remember, 6 ROWS (height) by 7 COLUMNS (width)" + - Explain the difference between board[row][col] indexing + + If needs_guidance: + - Show a SMALL example of a 2x3 board (not the full solution!) + - Explain nested lists/arrays conceptually + - Encourage them to try again + buckets: [excellent, correct, wrong_dimensions, needs_guidance, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + board_created: "true" + progress_score: "1" + next_section_and_step: "display_board:explain_display" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + board_created: "true" + progress_score: "1" + next_section_and_step: "display_board:explain_display" + wrong_dimensions: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "board_representation:implement_board" + needs_guidance: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "board_representation:implement_board" + set_language: + content_blocks: + - "Language preference updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "board_representation:implement_board" + + - section_id: "display_board" + title: "Step 2: Displaying the Board" + steps: + - step_id: "explain_display" + title: "Print the Board" + content_blocks: + - "# ๐Ÿ–จ๏ธ Step 2: Displaying the Board" + - "" + - "Great! You've created the data structure. Now we need to visualize it." + - "" + - "**The Challenge:** Turn your 2D array into a readable game board on screen." + - "" + - "**Concept: Nested Loops**" + - "- Outer loop: iterate through each row" + - "- Inner loop: iterate through each column in that row" + - "- Print each cell, then move to the next line after each row" + - "" + - "**Bonus Points:** Add column numbers (0-6) at the top or bottom to help players choose where to drop!" + + - step_id: "implement_display" + title: "Write Display Function" + question: "Write a function called display_board (or similar) that takes your board as a parameter and prints it in a readable format. Show each row and make it clear which positions are empty." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + The student should write a function that displays the board. + + Categorize as 'excellent' if they: + - Use nested loops correctly + - Print all rows and columns + - Make it readable (spacing, separators, column labels) + - Proper function syntax + + Categorize as 'correct' if they: + - Core logic is right (nested loops) + - Displays the board even if formatting is basic + - Function structure is correct + + Categorize as 'partial' if they: + - Have the concept but loops are wrong + - Or miss the function wrapper but logic exists + + Categorize as 'needs_help' if they're stuck on nested loops. + + Categorize as 'set_language' if switching languages. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent/correct: + - Celebrate: "Your board looks great! ๐ŸŽจ" + - Suggest enhancements like separators between cells: | or borders + - Note this function will be called after every move + + If partial: + - Identify what's working + - Guide them on the nested loop structure + - Explain outer loop = rows, inner loop = columns + + If needs_help: + - Explain nested loop concept clearly + - Give pseudocode (not full code): + for each row in board: + for each cell in row: + print cell + print newline + - Encourage them to try + buckets: [excellent, correct, partial, needs_help, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + display_implemented: "true" + progress_score: "n+1" + next_section_and_step: "drop_piece:explain_drop" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + display_implemented: "true" + progress_score: "n+1" + next_section_and_step: "drop_piece:explain_drop" + partial: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "display_board:implement_display" + needs_help: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "display_board:implement_display" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "display_board:implement_display" + + - section_id: "drop_piece" + title: "Step 3: Dropping a Piece" + steps: + - step_id: "explain_drop" + title: "Understanding Gravity" + content_blocks: + - "# ๐Ÿช‚ Step 3: Dropping a Piece (Gravity!)" + - "" + - "Now for the fun part: actually playing the game!" + - "" + - "**The Physics:** When you drop a piece in a column, it falls to the lowest empty space in that column." + - "" + - "**Algorithm Challenge:**" + - "1. Given a column number (0-6)" + - "2. Start from the BOTTOM row (row 5)" + - "3. Move UP until you find an empty space" + - "4. Place the piece there" + - "" + - "**Think about it:** If column 3 has pieces in rows 5, 4, and 3 (bottom three rows), the next piece drops into row 2." + - "" + - "**Tip:** You can iterate from the bottom up, or from top down and find the first empty, then check the one below is occupied." + + - step_id: "implement_drop" + title: "Write Drop Function" + question: "Write a function drop_piece(board, column, player) that drops a player's piece (e.g., 'X' or 'O') into the specified column. It should find the lowest empty row in that column and place the piece there. Return True if successful, False if the column is full." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + The student should implement the drop logic with gravity. + + Categorize as 'excellent' if they: + - Iterate through rows correctly (bottom-up or top-down) + - Find the lowest empty space + - Place the piece + - Return True/False or similar success indicator + - Handle full column edge case + + Categorize as 'correct' if they: + - Core gravity logic works + - Minor issues with iteration direction + - Concept is clearly understood + + Categorize as 'wrong_direction' if they: + - Place pieces at the top instead of letting them fall + - But understand they need to find an empty space + + Categorize as 'needs_guidance' if they're struggling with the algorithm. + + Categorize as 'set_language' for language changes. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent/correct: + - Celebrate: "Perfect! Gravity works! ๐ŸŒ" + - Explain how this function will be called each turn + - Mention: "This is the core game mechanic working!" + - Suggest they could add error checking (invalid column numbers) + + If wrong_direction: + - Point out pieces should FALL to the bottom + - Suggest: "Start checking from row 5 (bottom) and move up" + - Or: "Check from row 0 (top) down, but place in the LAST empty row" + + If needs_guidance: + - Walk through an example: "Column 2 is empty. Where does the first piece go? Row 5 (bottom)." + - "Second piece? Row 4. Third piece? Row 3." + - Give pseudocode for the loop structure + buckets: [excellent, correct, wrong_direction, needs_guidance, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + drop_implemented: "true" + progress_score: "n+1" + next_section_and_step: "validate_moves:explain_validation" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + drop_implemented: "true" + progress_score: "n+1" + next_section_and_step: "validate_moves:explain_validation" + wrong_direction: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "drop_piece:implement_drop" + needs_guidance: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "drop_piece:implement_drop" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "drop_piece:implement_drop" + + - section_id: "validate_moves" + title: "Step 4: Validating Moves" + steps: + - step_id: "explain_validation" + title: "Input Validation" + content_blocks: + - "# โœ… Step 4: Validating Moves" + - "" + - "Before dropping a piece, we need to check if the move is legal!" + - "" + - "**Invalid Moves:**" + - "1. Column number is out of range (< 0 or > 6)" + - "2. Column is already full (all 6 rows occupied)" + - "" + - "**Why This Matters:** Without validation, your game will crash or behave unexpectedly when players make mistakes." + - "" + - "**Good User Experience:** Tell players WHY their move was invalid and let them try again." + + - step_id: "implement_validation" + title: "Write Validation Function" + question: "Write a function is_valid_move(board, column) that returns True if the move is valid (column is in range 0-6 and not full), False otherwise. Bonus: Write a function get_player_move() that keeps asking until the player enters a valid column." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + Categorize as 'excellent' if they: + - Check column range (0-6) + - Check if column has any empty space + - Return boolean correctly + - Bonus: Implement get_player_move with retry loop + + Categorize as 'correct' if they: + - Have validation logic for both conditions + - Function structure is correct + - Minor syntax issues okay + + Categorize as 'partial' if they: + - Only check one condition (range OR fullness) + - Concept understood but incomplete + + Categorize as 'needs_help' if struggling with the logic. + + Categorize as 'set_language' for language changes. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent: + - Celebrate: "Excellent validation! Your game is robust! ๐Ÿ’ช" + - If they did the bonus: "Love the input loop - great UX!" + - Point out how this prevents crashes and improves player experience + + If correct: + - Praise: "Great! Your validation works!" + - If they didn't do the bonus, mention it would be a nice addition + + If partial: + - Identify what they got right + - Explain what's missing (range check or fullness check) + - Encourage them to add the missing piece + + If needs_help: + - Break it down: "Two checks needed:" + - "1. Is 0 <= column <= 6?" + - "2. Is the top row (row 0) of that column empty?" + - Provide pseudocode structure + buckets: [excellent, correct, partial, needs_help, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + validation_implemented: "true" + progress_score: "n+1" + next_section_and_step: "horizontal_win:explain_horizontal" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + validation_implemented: "true" + progress_score: "n+1" + next_section_and_step: "horizontal_win:explain_horizontal" + partial: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "validate_moves:implement_validation" + needs_help: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "validate_moves:implement_validation" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "validate_moves:implement_validation" + + - section_id: "horizontal_win" + title: "Step 5: Checking Horizontal Wins" + steps: + - step_id: "explain_horizontal" + title: "Win Detection - Horizontal" + content_blocks: + - "# ๐Ÿ† Step 5: Detecting Horizontal Wins" + - "" + - "Now for the game logic - determining when someone wins!" + - "" + - "**Horizontal Win:** 4 identical pieces in a row (same row, consecutive columns)" + - "" + - "**Algorithm Strategy:**" + - "1. For each row (0-5)" + - "2. For each starting column (0-3) - why only 0-3? Because you need 4 consecutive!" + - "3. Check if board[row][col], board[row][col+1], board[row][col+2], board[row][col+3] are all the same player" + - "" + - "**Key Insight:** You only need to check columns 0-3 as starting positions. If you start at column 4, you can't fit 4 pieces!" + + - step_id: "implement_horizontal" + title: "Write Horizontal Check" + question: "Write a function check_horizontal_win(board, player) that returns True if the specified player has 4 in a row horizontally, False otherwise. Iterate through all rows and check consecutive columns." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + Categorize as 'excellent' if they: + - Iterate rows (0-5) correctly + - Iterate columns (0-3) as starting positions + - Check 4 consecutive positions + - Compare against player symbol + - Return True when found, False at end + + Categorize as 'correct' if they: + - Logic is sound + - Might iterate all columns but still works + - Core concept demonstrated + + Categorize as 'wrong_bounds' if they: + - Iterate columns 0-6 (causing index errors) + - But understand the consecutive checking concept + + Categorize as 'needs_guidance' if struggling with the nested loops or logic. + + Categorize as 'set_language' for language changes. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent: + - Celebrate: "Perfect! Horizontal wins are detected! ๐ŸŽ‰" + - Mention: "Your optimization (only checking columns 0-3) is smart!" + - Hint at what's next: "Vertical and diagonal will use similar patterns" + + If correct: + - Praise: "Great logic!" + - If they checked all columns unnecessarily, gently suggest the optimization + - Still move them forward + + If wrong_bounds: + - Point out the index error: "Checking column 6 means accessing [row][6+3] which doesn't exist!" + - Explain: "If you start at column 4, you check positions 4,5,6,7 - but column 7 doesn't exist" + - Suggest: "Only iterate columns 0-3" + + If needs_guidance: + - Walk through a concrete example + - "Row 2, starting at column 1: check [2][1], [2][2], [2][3], [2][4]" + - Provide pseudocode structure + buckets: [excellent, correct, wrong_bounds, needs_guidance, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + horizontal_implemented: "true" + progress_score: "n+1" + next_section_and_step: "vertical_win:explain_vertical" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + horizontal_implemented: "true" + progress_score: "n+1" + next_section_and_step: "vertical_win:explain_vertical" + wrong_bounds: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "horizontal_win:implement_horizontal" + needs_guidance: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "horizontal_win:implement_horizontal" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "horizontal_win:implement_horizontal" + + - section_id: "vertical_win" + title: "Step 6: Checking Vertical Wins" + steps: + - step_id: "explain_vertical" + title: "Win Detection - Vertical" + content_blocks: + - "# ๐Ÿ“ Step 6: Detecting Vertical Wins" + - "" + - "Similar to horizontal, but now we're checking columns instead of rows!" + - "" + - "**Vertical Win:** 4 identical pieces stacked vertically (same column, consecutive rows)" + - "" + - "**Algorithm Strategy:**" + - "1. For each column (0-6)" + - "2. For each starting row (0-2) - why only 0-2? Same reason as before!" + - "3. Check if board[row][col], board[row+1][col], board[row+2][col], board[row+3][col] are all the same player" + - "" + - "**Pattern Recognition:** Notice how this mirrors the horizontal check, just with rows and columns swapped?" + + - step_id: "implement_vertical" + title: "Write Vertical Check" + question: "Write a function check_vertical_win(board, player) that returns True if the specified player has 4 in a row vertically. Use the same logic as horizontal, but swap rows and columns." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + Categorize as 'excellent' if they: + - Iterate columns (0-6) correctly + - Iterate rows (0-2) as starting positions + - Check 4 consecutive rows in same column + - Compare against player symbol + - Return boolean correctly + + Categorize as 'correct' if they: + - Logic works + - Might iterate all rows but function still works + - Understand the pattern + + Categorize as 'wrong_bounds' if they: + - Iterate rows 0-5 (causing index errors on row+3) + - But the checking logic is right + + Categorize as 'needs_guidance' if struggling. + + Categorize as 'set_language' for language changes. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent: + - Celebrate: "Vertical wins detected! ๐Ÿ“ You're seeing the patterns!" + - Mention: "Notice how similar this is to horizontal? Same algorithm, different direction!" + - Build anticipation: "Diagonal is the trickiest one next!" + + If correct: + - Praise: "Great work!" + - If they checked all rows, gently suggest the optimization + - Acknowledge they're building momentum + + If wrong_bounds: + - Explain the index issue with row+3 exceeding bounds + - Suggest: "Only start from rows 0-2" + + If needs_guidance: + - Remind them of horizontal logic + - "It's the same pattern, just checking board[row+i][col] instead of board[row][col+i]" + - Provide structure + buckets: [excellent, correct, wrong_bounds, needs_guidance, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + vertical_implemented: "true" + progress_score: "n+1" + next_section_and_step: "diagonal_win:explain_diagonal" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + vertical_implemented: "true" + progress_score: "n+1" + next_section_and_step: "diagonal_win:explain_diagonal" + wrong_bounds: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "vertical_win:implement_vertical" + needs_guidance: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "vertical_win:implement_vertical" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "vertical_win:implement_vertical" + + - section_id: "diagonal_win" + title: "Step 7: Checking Diagonal Wins" + steps: + - step_id: "explain_diagonal" + title: "Win Detection - Diagonals" + content_blocks: + - "# โ†—๏ธ Step 7: Detecting Diagonal Wins (The Tricky One!)" + - "" + - "Diagonals are the most challenging because there are TWO directions to check!" + - "" + - "**Two Types of Diagonals:**" + - "1. **Down-Right (โ†˜๏ธ):** row increases, column increases (row+1, col+1)" + - "2. **Up-Right (โ†—๏ธ):** row decreases, column increases (row-1, col+1)" + - "" + - "**Down-Right Diagonal:**" + - "- Starting row range: 0-2 (need room to go down 3 rows)" + - "- Starting column range: 0-3 (need room to go right 3 columns)" + - "- Check: [row][col], [row+1][col+1], [row+2][col+2], [row+3][col+3]" + - "" + - "**Up-Right Diagonal:**" + - "- Starting row range: 3-5 (need room to go up 3 rows)" + - "- Starting column range: 0-3 (need room to go right 3 columns)" + - "- Check: [row][col], [row-1][col+1], [row-2][col+2], [row-3][col+3]" + + - step_id: "implement_diagonal" + title: "Write Diagonal Check" + question: "Write a function check_diagonal_win(board, player) that returns True if the player has 4 in a row diagonally (either direction). You need to check both down-right (โ†˜๏ธ) and up-right (โ†—๏ธ) diagonals." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + This is the hardest check! Be generous with partial credit. + + Categorize as 'excellent' if they: + - Check BOTH diagonal directions + - Correct row/column bounds for each direction + - Proper indexing (rowยฑi, col+i) + - Return True when found + + Categorize as 'correct' if they: + - Have both directions + - Logic is mostly right + - Minor boundary or indexing issues but concept clear + + Categorize as 'one_direction' if they: + - Only implement one diagonal direction + - But that direction is implemented correctly + + Categorize as 'needs_guidance' if they're struggling with the concept. + + Categorize as 'set_language' for language changes. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent: + - Celebrate enthusiastically: "๐ŸŽ‰ You conquered diagonals! This is the hardest part!" + - Praise: "Both directions working correctly - impressive!" + - Mention: "Win detection is now COMPLETE! Your game knows when someone wins!" + + If correct: + - Praise: "Great work on the tricky diagonal logic!" + - If minor issues, point them out gently + - Still acknowledge this is hard and they did well + + If one_direction: + - Praise what they did: "Excellent work on [direction] diagonals!" + - Explain: "Connect Four needs both directions: โ†˜๏ธ and โ†—๏ธ" + - Guide them on the second direction's bounds and indexing + + If needs_guidance: + - Break down one diagonal type completely + - "Down-right example: start at [0][0], check [0][0], [1][1], [2][2], [3][3]" + - "Start at [1][2], check [1][2], [2][3], [3][4], [4][5]" + - Provide pseudocode structure + buckets: [excellent, correct, one_direction, needs_guidance, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + diagonal_implemented: "true" + progress_score: "n+1" + next_section_and_step: "game_loop:explain_loop" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + diagonal_implemented: "true" + progress_score: "n+1" + next_section_and_step: "game_loop:explain_loop" + one_direction: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "diagonal_win:implement_diagonal" + needs_guidance: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "diagonal_win:implement_diagonal" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "diagonal_win:implement_diagonal" + + - section_id: "game_loop" + title: "Step 8: Building the Game Loop" + steps: + - step_id: "explain_loop" + title: "Putting It All Together" + content_blocks: + - "# ๐Ÿ”„ Step 8: The Game Loop" + - "" + - "You have ALL the pieces! Now let's assemble them into a playable game." + - "" + - "**Game Loop Structure:**" + - "1. Initialize the board" + - "2. Set current player (start with Player 1)" + - "3. **Loop until game ends:**" + - " - Display the board" + - " - Get current player's move (with validation)" + - " - Drop the piece" + - " - Check if current player won (all 3 directions)" + - " - Check if board is full (tie)" + - " - Switch to other player" + - "4. Display final board and announce winner" + - "" + - "**Key Concepts:**" + - "- **Game state:** The board changes each turn" + - "- **Turn alternation:** Switch between players" + - "- **Exit condition:** Win or tie breaks the loop" + + - step_id: "implement_loop" + title: "Write Game Loop" + question: "Write the main game loop that brings everything together. Initialize the board, alternate between two players, validate moves, drop pieces, check for wins, and announce the winner. You can write this as a play_game() function or as main program logic." + tokens_for_ai: | + Get the programming language from metadata.programming_language. + + They're writing the FULL game now! Be encouraging. + + Categorize as 'excellent' if they: + - Initialize board + - Have a game loop (while/for loop until game ends) + - Alternate between players + - Call display, input, validation, drop, and win check functions + - Handle both win and tie conditions + - Announce results + + Categorize as 'correct' if they: + - Have the main structure + - Loop with turn alternation + - Call their functions appropriately + - Minor logic issues okay if concept is clear + + Categorize as 'partial' if they: + - Have some of the structure + - Missing key parts (like win checking or player switching) + - On the right track but incomplete + + Categorize as 'needs_guidance' if they're struggling to put it together. + + Categorize as 'set_language' for language changes. + feedback_tokens_for_ai: | + Provide feedback in metadata.programming_language. + + If excellent: + - CELEBRATE BIG: "๐ŸŽ‰๐ŸŽฎ YOU DID IT! You built a complete Connect Four game!" + - List what they've accomplished: + * Board representation with 2D arrays + * Display with nested loops + * Gravity simulation for dropping pieces + * Input validation + * Win detection in 3 directions + * Full game loop with turn management + - Suggest enhancements: AI opponent, GUI, undo moves, score tracking + - Congratulate them on completing a non-trivial project! + + If correct: + - Celebrate: "Your game works! Excellent job! ๐ŸŽ‰" + - Point out any minor improvements + - Still emphasize they built something real and playable + + If partial: + - Praise what's working + - Identify what's missing + - Guide them: "You have X and Y working. Now add Z to complete the loop." + - Encourage: "You're so close!" + + If needs_guidance: + - Break down the loop structure + - "Think of it as: setup -> loop (input, validate, drop, check, switch) -> end" + - Provide high-level pseudocode + - Encourage them to try integrating one piece at a time + buckets: [excellent, correct, partial, needs_guidance, set_language] + transitions: + excellent: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + game_complete: "true" + progress_score: "n+1" + next_section_and_step: "conclusion:reflection" + correct: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + game_complete: "true" + progress_score: "n+1" + next_section_and_step: "conclusion:reflection" + partial: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "game_loop:implement_loop" + needs_guidance: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + next_section_and_step: "game_loop:implement_loop" + set_language: + content_blocks: + - "Language updated!" + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "game_loop:implement_loop" + + - section_id: "conclusion" + title: "Conclusion & Reflection" + steps: + - step_id: "reflection" + title: "What You've Learned" + question: "Reflect on what you learned. What was the most challenging part? What concepts (2D arrays, loops, algorithms, etc.) do you feel more confident about now? What would you add to your game next?" + tokens_for_ai: | + This is a reflection question. Accept any thoughtful response. + + Categorize as 'thoughtful' if they: + - Reflect on specific challenges (likely diagonals!) + - Mention concepts they learned + - Show understanding of what they built + - Maybe mention enhancements + + Categorize as 'brief' if they: + - Give a short but genuine response + - Show they completed the project + + Categorize as 'off_topic' if they: + - Don't engage with the reflection + - Are completely off-topic + + Categorize as 'set_language' for language changes (though activity is ending). + feedback_tokens_for_ai: | + Provide encouraging, celebratory feedback. + + For thoughtful responses: + - Acknowledge their specific insights + - Validate that diagonals ARE the hardest part + - Encourage them to implement their enhancement ideas + - Mention how these concepts (2D arrays, nested loops, algorithms) apply to many other programs + - Celebrate their achievement of building a complete game from scratch + + For brief responses: + - Thank them for their time + - Celebrate their completion + - Encourage them to keep coding + + For off_topic: + - Gently redirect to the question + - Ask them to reflect on the experience + buckets: [thoughtful, brief, off_topic, set_language] + transitions: + thoughtful: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + activity_completed: "true" + next_section_and_step: "conclusion:goodbye" + brief: + ai_feedback: + tokens_for_ai: "See feedback_tokens_for_ai above" + metadata_add: + activity_completed: "true" + next_section_and_step: "conclusion:goodbye" + off_topic: + content_blocks: + - "Let's take a moment to reflect on what you learned building Connect Four." + next_section_and_step: "conclusion:reflection" + set_language: + content_blocks: + - "Language updated! Though we're at the end of the activity." + metadata_add: + programming_language: "the-users-response" + counts_as_attempt: false + next_section_and_step: "conclusion:reflection" + + - step_id: "goodbye" + title: "Congratulations!" + content_blocks: + - "# ๐ŸŽ‰ Congratulations! You Built Connect Four! ๐ŸŽฎ" + - "" + - "You've successfully created a fully functional Connect Four game from scratch!" + - "" + - "**What You Accomplished:**" + - "โœ… Mastered 2D arrays and nested data structures" + - "โœ… Implemented game physics (gravity!)" + - "โœ… Wrote input validation" + - "โœ… Designed win-detection algorithms in 3 directions" + - "โœ… Built a complete game loop with state management" + - "โœ… Created something you can actually play!" + - "" + - "**Next Steps:**" + - "- Add an AI opponent (minimax algorithm?)" + - "- Create a graphical interface (GUI)" + - "- Add animations for falling pieces" + - "- Implement undo/redo" + - "- Add different board sizes" + - "" + - "Keep building! Every complex program is just these same concepts combined in creative ways. ๐Ÿš€" + - "" + - "Happy coding!"