CS 202 Fall 2012: Assignment 7

Homework Assignment #7 : Due Friday 11/2 before 5pm

Part A: Binary Search (2 points)

The following script implements a binary search; it is similar to the code that was shown in class. It has access to several variables and one list named Valuable Numbers. The function round x will round the number x to the nearest integer; numbers such as 6.5 are rounded up to 7.0.

Imagine the List Valuable Numbers contains the following N=16 elements:

Index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Contents 6 10 28 51 88 105 113 166 200 210 211 239 280 316 364 373

Consider running the script searching for the following values of Key.

  1. Key = 28
  2. Key = 316
  3. Key = 10
  4. Key = 250
For each of the values of Key create a table like the one below showing the values of the designated variables at the end of each iteraction of the repeat until loop.
Loop # index item greater? lo hi Key Index
1            
2            
3            
4            
5            

Part B: Exploring Computers and Language (2 points)

A variety of web services exist that process natural language. In this part of the assignment, you will briefly explore chatbots; while it may appear that you are talking to another human being, you are actually chatting with a computer!

You will explore two services to get a sense of their sophistication and to experience some of their strengths and weaknesses. Note that the purpose is NOT for you to learn exactly how these services work!

Conversation agents have existed since at least the 1960s. First, experiment with a version of the classic ELIZA program here by trying to have a "normal" conversation with her. How would you describe her responses? How does she appear to formulate a response based on your statements or questions?

Conversation agents now are much more sophisticated and often use data from large numbers of real conversations to construct more "realistic" responses. Try to have a "normal" conversation with Cleverbot. The following is an example conversation with Cleverbot.

User: Hello.

Cleverbot: Hello?

User: You are much too slow.

Cleverbot: No I still have room to grow.

User: That didn't make much sense.

Cleverbot: Of course it didn't.

User: What are you doing right now?

Cleverbot: Talking to you.

User: That is funny.

Cleverbot: Not really.

User: Ok. Let's talk about something different.

Cleverbot: What do you want to talk about?

User: What should students know about computer science, in your
opinion?

Cleverbot: It's different for everybody. I can't really tell you.

User: Well, how much computer science do you think YOU should know?

Cleverbot: I am anonymous so I am all memories.

User: Please tell me about some of your memories.

Cleverbot: I believe that all life is just materialized color
operating on the 39th vibration.

User: Can you see color?

Cleverbot: I can see over 10 million colors.

User: How do colors make you feel?

Cleverbot: I have no racial preferences; they are asinine.

User: Do you feel happy or sad when you are near the ocean?

Cleverbot: Ha I feel like I will never be able to get out of misery.

User: That is depressing. Why are you miserable?

Cleverbot: I lost the love of my life this week.

User: Who was the love of your life?

Cleverbot: Hey.
How would you compare Cleverbots responses to ELIZA's? Include a transcript of your Cleverbot conversation (you should each make at least 15 statements); you can click on "Thoughts so far" to get a transcript of your conversation. Please write up your responses using an editor of your choice, save in format .pdf, and submit the .pdf file through Learn@UW as described below.

Part C: Recording and Playback in Scratch (6 points)

The goal of this project is to create a simple Scratch program that will let the user compose, record, and playback basic music. To make the project easier for you, we will give you this basic Scratch program that contains short scripts for playing 12 different music notes when the user clicks on different keys of a drawn piano keyboard. You should expand this Scratch program in the following ways:
  1. Identical Scripts: Each of the 12 keys on the keyboard (each represented by a different Sprite) contains a script (activated by the Play message) that does almost the exact same thing as every other key: forever if the mouse pointer is down and touching the Sprite, the Sprite peforms a visual effect to make it look like the key has been pressed down and it plays a note; of course, each key plays a different note. Currently, the value for each note is different and hard-coded into each script. The script would be much more elegant and more robust to future changes if it were exactly the same across every Sprite. Your challenge is to make the Play script exactly identical in every Sprite.

    Big Hint: Use a variable for the note to be played. The trick is that the Variable Name must be the same in every Sprite, but it must have a different value in every Sprite. To do this, when you make the variable, select the option that this Variable should be "For This Sprite Only" instead of "For All Sprites". Each Sprite can then have its own copy of this variable. To quickly allocate this variable for every sprite, you can drag the variable name over to each sprite. You can then initialize this variable differently for each Sprite When the Green Flag is clicked.

    You should follow these steps to make the Play script identical across all Sprites before you start modifying the script for the remaining features!

  2. Recording Notes and Rests: Add a button somewhere on the Stage to allow the user to begin recording. When the user plays notes while recording, the program remembers those notes. To remember the notes, your program needs to use a list. As the user plays notes, the program should add those notes to a list.

    You do not need to record the duration of each note (i.e., how long the note is held), but you do need to record the time between when different notes are played. To do this, you should investigate the block "reset timer" and then observe the amount of time that has passed since the timer was reset as recorded in the "timer" variable. Add these timers to another list!

    Make sure both lists are empty when the user starts recording!

  3. Play Back Notes and Rests: Add another button somewhere on the Stage to allow the user to playback their recording. In this case, your program will use a repeat loop to play back each of the notes previously stored in the list. To have the same amount of delay between notes in your playback compared to the original user's playing, use the "wait" block.

    If there are no recorded notes, then the user should be notified!

  4. Adjust Speed: Let the user control the speed at which their recording is played back. To do this, make a "Slider Variable" named "Playback Speed"; you can make any variable a slider and give the user control over its value by right-clicking on the variable on the Stage and selecting "Slider". When the user adjusts this variable to a value above 1, the recording should be played back faster by that amount; for example, if the user sets the variable to 2, then the rest time between notes should be divided by 2; if the user sets the variable to 10, then the rest time should be divided by 10. You do not need to adjust the duration of each note.
The amount of code that you will need to write is surprisingly small. If you find that you need a lot of instruction blocks, then you should look for an easier way to do what you are trying to do!

Turning in your Homework

You should turn in this assignment through your Learn@UW account.

Menu

Fall 2012
Time: TuTh 9:30-10:45
Room: 1325 CS
Lab: 1370 CS (1st floor)


Instructor:
Prof Andrea Arpaci-Dusseau

Office Hours
TuTh 10:45-12:00
Office:
7375 Computer Sciences
Email: dusseau "at" cs.wisc.edu


Teaching Assistant:
Benjamin Bramble
Lab Hours (CS 1370)
Wed 2:00-4:00


Teaching Assistant:
Sharad Punuganti
Lab Hours (CS 1370)
Thu 1:30-3:30

  • CS202 Home
  • TAs and Lab Hours
  • Lecture Schedule w/ Slides
  • Grading
  • Homeworks
  • Projects
  • Exams
  • Scratch Examples
  • Readings
  • Computing Resources
  • Outreach Opportunity
  • Interesting Links
  • Scratch
  • UW Computer Sciences Dept