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 ID: 300718
Download Presentation The PPT/PDF document "Lab 3: Conditionals and Artificial Intel..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Lab 3: Conditionals and Artificial Intelligence
Jan. 27 – Jan. 31Slide2
Review-Activity 2: Brick WallSlide3
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 &
lt
; >” Repeat until the condition is True. You will use predicate blocks which can be found in the Operator PaletteSlide4
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.Slide5
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 guessesStep 5 – Report number of guesses to playerSlide6
Step 1: Welcome PlayerRemember from Lab1, when we created a script for the sprite to ask our name!Slide7
Step 1: Build ScriptLet’s look at our algorithm…Slide8
Step 1: Build ScriptSlide9
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…Slide10
Step 2: Inform your player
Remember there is more than one way to do this!Slide11
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” valueSlide12
Step 3: Allow choice of max
Make a variable for “max”Slide13
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.Slide14
Step 4: Count number of guessesSlide15
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!Slide16
Step 5: ReportSlide17
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*** Slide18
Activity 2: Guessing Game 2.0