Lab 3: Conditionals and Artificial Intelligence Jan. 27 – Jan. 31
Lab 3: Conditionals and Artificial Intelligence
Jan. 27 – Jan. 31
Review-Activity 2: Brick Wall
Looping Blocks There are times when you will want blocks to
repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there are looping control blocks that you can wrap around the script you want to repeat.› “forever” – loops until the program ends. This is
basically an infinite loop as it goes on forever.› “repeat ()”- loops the specified number of times.› “repeat until < >” Repeat until the condition is
True. You will use predicate blocks which can be found in the Operator Palette
Repeat Until
Let’s look at the “repeat until” block a bit closer.
› Just like REPEAT, it will do everything inside the C- shaped block a certain number of times.
However before it starts the loop each time, it checks to see if the condition (x > 5) is true. When this is condition is true, it will not repeat again.
Creating a Guessing Game
Step 1 – Welcome Player, build Script!
Step 2 – Inform Player about their guess
Step 3 – Allow player to choose max value
Step 4 – Count number of guesses
Step 5 – Report number of guesses to player
Step 1: Welcome Player
Remember from Lab1, when we created a script for the sprite to ask our name!
Step 1: Build Script
Let’s look at our algorithm…
Step 1: Build Script
Step 2: Inform Player
We want to give the player more information if they don’t guess correctly.
Have the sprite tell the player if the secret number is bigger or smaller than the number that they guessed.
Work with your neighbor to add to your script…
Step 2: Inform your player
Remember there is more than one way to do this!
Step 3: Allow Choice of Max
Change your code so that the player choose the max value, instead of the sprite choosing a number between 1 and 10
Use this maximum number as the highest number that the sprite will choose.
Hint: Make a new variable for “max” value
Step 3: Allow choice of max
Make a variable for “max”
Step 4: Count number of guesses
Now let’s keep track of how many guesses it takes before the player guesses the right number.
You will need a new variable for this task and will need to add to it every time a guess occurs.
Step 4: Count number of guesses
Step 5: Report
When the player guesses the secret number tell them how many guesses it took, and congratulate them using their name.
Hint: Use previous variables!
Step 5: Report
Activity 3: Guessing Game 2.0
The goal of this Expanded Guessing Game (we’ll call it, version 2.0) is to make sprites that play the game smarter!› Create two sprites to play the game
Guide sprite Guesser sprite
› Create a list› Follow the 5 steps outlined in Manual 3.
***DUE: 48hrs after lab***
Activity 2: Guessing Game 2.0