Top Banner
Lab 3: Conditionals and Artificial Intelligence Jan. 27 – Jan. 31
18

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.

Jan 05, 2016

Download

Documents

Beverly Conley
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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.

Lab 3: Conditionals and Artificial Intelligence

Jan. 27 – Jan. 31

Page 2: 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.

Review-Activity 2: Brick Wall

Page 3: 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.

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

Page 4: 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.

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.

Page 5: 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.

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

Page 6: 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.

Step 1: Welcome Player

Remember from Lab1, when we created a script for the sprite to ask our name!

Page 7: 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.

Step 1: Build Script

Let’s look at our algorithm…

Page 8: 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.

Step 1: Build Script

Page 9: 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.

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…

Page 10: 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.

Step 2: Inform your player

Remember there is more than one way to do this!

Page 11: 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.

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

Page 12: 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.

Step 3: Allow choice of max

Make a variable for “max”

Page 13: 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.

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.

Page 14: 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.

Step 4: Count number of guesses

Page 15: 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.

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!

Page 16: 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.

Step 5: Report

Page 17: 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.

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***

Page 18: 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.

Activity 2: Guessing Game 2.0