CS106A
Winter 2013-2014
Handout #06
January 8, 2014 Assignment 1: Email and Karel the Robot
_________________________________________________________________________________________________________
Bad on a handout by Eric Roberts and Mehran Sahami In this first assignment, you'll e just how powerful Karel the Robot can be as you u him to solve a variety of programming problems. But first, Keith and Vikas would really like to meet you! Since we'll be using email as a primary means of communication in this cour, we'd like it if you could take the time to nd us an email introducing yourlf. This assignment consists of two parts:
Email Us!Due Sunday, January 19 at 11:59PM
Karel the Robot Due Friday, January 17 at 3:15PM
Karel Writeup Due Friday, January 17 at 3:15PM
Part One: Email Us! (Due Sunday, January 19 at 11:59PM)
We'd love to get to know you in CS106A! As your first task, we'd like you to nd an email to Keith (htiek@cs.stanford.edu), head TA Vikas (vikasuy@cs.stanford.edu), and your ction leader. Note that you won't know your ction leader's email address until after your first ction, which is why we don't make this part of the assignment due until Sunday. Plea make sure that the subject line of your email says “CS106A Email: <your name>”, where “<your nam e>” is actually filled in with your name. The message should also include answers to the questions below.
Note: None of the items in your email to us are binding (i.e., you can always change which platform you work on). The point of this assignment is just for us to learn a little more about you!
Questions to answer in your email to us:
General information and computing background:
1.What is your name?
2.What year are you? (Frosh, Sophomore, Junior, Senior, Graduate, Other)
3.Which ction (10:00AM or 3:15PM) of CS106A are you enrolled in?
4.What is your major/area of study?(“I'm not sure” and “I don't know” are completely
acceptable answers here!)
5.What type of computer (PC, Mac, Linux, etc.) do you prefer using?
6.What is your gender?
7.Why are you taking CS106A?
Fun Stuff: This final ction is just for us to have something to remember you by.
海虹的营养价值及功效
1.What do you do for fun?
2.Tell a quick anecdote about something that you feel makes you unique. This can be a cool
talent, an interesting experience, or anything el you'd like!
3.Computers can be ud to solve a wide variety of problems and perform a huge range of
tasks. Is there any particular application of computers you'd like us to cover in this cour?
Part Two (The Real Assignment): Karel the Robot
The meat of this assignment consists of four Karel programs. There is a starter project including all of the problems on the CS106A web site in the area for Assignment 1. To work on the programs, download that starter folder as described in Handout #05 (Using Karel in Eclip). From there, you can edit the program files so that the assignment actually does what it’s suppod to do, which will involve a cycle of coding, testing, and debugging until everything works. The final step is to submit your as-signment using the Submit Project entry under the Stanford Menu. You can submit your programs as you finish them and that you can submit more than one version of your project. If you discover an error after you’ve submitted one of the problems, just fix your program and submit a new copy.
Also, plea remember that your Karel programs must limit themlves to the language features described in Karel the Robot Learns Java in the Karel and SuperKarel class. You may not u other features of Java, even though the Eclip-bad version of Karel accepts them.
We recommend reading through Handout #03 about the Stanford Honor Code before starting this as-signment to make sure that you are aware of our Honor Code policies.
Problem 1: CollectNewspaperKarel
Your first task is to solve a simple story-problem in Karel’s world. Suppo that Karel has ttled into its hou, which is the square area in the center of the following diagram:
1234567
1
2
3
4
5
Karel starts off in the northwest corner of its hou as shown in the diagram. The problem you need to get Karel to solve is to collect the newspaper – reprented (as all objects in Karel’s world are) by a beeper – from outside the doorway and then to return to its initial position.
This exerci is extremely simple and exists just to get you started. You can assume that every part of the world looks just as it does in the diagram. The hou is exactly this size, the door is always in the position shown, and the beeper is just outside the door. Thus, all you have to do is write the quence of commands necessary to have Karel
1.Move to the newspaper,
2.Pick it up, and
3.Return to its starting point.
Even though the program is only a few lines, it is still worth getting at least a little practice in decom-
position. In your solution, include a private method for each of the steps shown in the outline.A Word of Advice
Before you go on to the harder problems on this assignment, why don’t you try submitting your project as soon as you are done with this first problem? Every year, a handful of students run into some kind of problem with the electronic submission option provided in the Stanford version of Eclip. If you wait until 3:00P .M . the day the assignment is due to submit any of your work, you may discover that there is some aspect of the submission process that you didn’t quite understand only after it’s too late to get any help. So right now, as soon as you’ve got this first program working (and as soon as you get a ction assignment), go ahead and hit the submit button to make sure that you can ship things off. Once you’ve done so, you’ll know that you’ve got the submission process under control. Remember, we only look at the last submission you make before the due date, so it doesn’t hurt to submit new versions of your solution as you finish them.
Problem 2: StoneMasonKarel
萱萱小游戏Karel has been hired to repair the damage done to the Quad in the 1989 earthquake. In particular, Karel is to repair a t of arches where some of the stones (reprented by beepers, of cour) are missing from the columns supporting the arches, as follows:
1
2
3
4
5
6
7
8
When Karel is done, the missing stones in the columns should be replaced by beepers, so that the final picture resulting from the world shown above would look like this:
电信宽带密码
12345678910111213
1
2
3
4
5
6
7
8
Your program should work on the world shown above, but it should be general enough to handle any world that meets certain basic conditions as outlined at the end of this problem. There are veral ex-ample worlds in the starter folder, and your program should work correctly with all of them.
Karel’s final location and the final direction he is facing at end of the run do not matter. Karel may count on the following facts about the world, listed below:
•Karel starts at 1st Avenue and 1st Street, facing east, with an infinite number of beepers in Karel’s beeper bag.
•The columns are exactly four units apart, on 1st, 5th, 9th Avenue, and so forth.
世界港口查询
•The end of the columns is marked by a wall immediately after the final column. This wall c-tion appears after 13th Avenue in the example, but your program should work for any number of columns.
•The top of the column is marked by a wall, but Karel cannot assume that columns are always five units high, or even that all columns are the same height.
元丰六年
•
Some of the corners in the column may already contain beepers reprenting stones that are still in place. Your program should not put a cond beeper on the corners.Problem 3: CheckerboardKarel
In this exerci, your job is to get Karel to create a checkerboard pattern of beepers inside an empty rectangular world, as illustrated in the following before-and-after diagram. (Karel’s final location and the final direction it is facing at end of the run do not matter.)点读机原理
糍饭
123456781
2
3
4
5
6
7winter
8
Before
1234567
8After
As you think about how you will solve the problem, you should make sure that your solution works with checkerboards that are different in size from the standard 8x 8 checkerboard shown in the exam-ple. Odd-sized checkerboards are tricky, and you should make sure that your program generates the fol-lowing pattern in a 5x 3 world:
1
2
3
1234
5
Another special ca you need to consider is that of a world which is only one column wide or one ro
w high. The starter folder contains veral sample worlds that test the special cas, and you should make sure that your program works for each of them.