CS108L Spring 2014

Week 1 - Do Now Questions: Agent Movement

1.  Question: After performing this procedure, where will a turtle that started at (0,0) with heading 0 end up?


to move-it
right 180
forward 20
left 90
forward 30
back 35
end

a)  (5, -20) with heading 0;

b)  (-5, 20) with heading 90;

c)  (5, 20) with heading 90;

d)  (-5, -20) with heading 90


Answer: b) (-5, -20) with heading 90

Explanation: It is easy to confuse headings and the turns that turtles make. The headings are the cardinal directions N,S,E and W –but instead of North we say 0, instead of East we say 90, etc. Here is a diagram:

Notice that the turtle starts pointing North (0) turns 180 degrees (now pointing South, 180) forward 20—so switching now to Cartesian coordinates, twenty step South changes our y coordinate to -20. Our current position, (0, -20). Turning left 90 faces us East again (I use a pencil on the table to visualize this turn)—now forward 30 and back 35 is about the same as just going back 5. We are moving only on the x axis now. We are at (-5, -20).

2.  Question: After performing this procedure, where will a turtle that started at (0,0) with heading 0 end up?


to move-it
right 90
forward 20
left 90
forward 30
left 90
forward 10
end

a)  (0, -20) with heading 270;

b)  (30, 0) with heading 90;

c)  (20, 30) with heading 90;

d)  (10, 30) with heading 270

Answer: d) (10, 30) with heading 270


Sketch makes it clearer. Notice 30 in the positive x direction, and a net of positive 10 on the y axis.

3.  Question: After performing this procedure, where will a turtle that started at (5, 20) with heading 90 end up?


to move-it
right 90
forward 10
right 90
forward 25
right 270
forward 10
end

a)  (-20, 0) with heading 0;

b)  (-20, 0) with heading 180;

c)  (-40, 30) with heading 270;

d)  (-30, -40) with heading 90

Answer: b) (-20, 0) with heading 180

Sometimes it is pretty easy to make a quick little NetLogo program to see the answer. Here’s one that I wrote.

4.  Question: This procedure is intended to have a turtle draw an equilateral triangle with side length 10, but it doesn’t work as intended. What is wrong?


to draw-triangle
pen-down
right 120
forward 10
right 120
forward 10
right 120
pen-up
end

a)  there are too many forward movements;

b)  there should be only 2 turns;

c)  there should be 3 forward movements and 2 turns;

d)  no errors are present


Answer: c) there should be 3 forward movements and 2 turns

Copying and pasting this into the little program that I made for Question 3. Showed me this:


5.  Question: Predict what a turtle will do when the following procedure is run.

to draw-me
pen-down
forward 10
pen-up
forward 5
pen-down
forward 10
pen-up
end

a)  it draws a continuous straight line;

b)  it draws a line of length 25;

c)  it draws a zigzag;

d)  it draws a dashed line

Answer: d) it draws a dashed line

Pen down and pen up and pen down means a dashed line.

CS108L_Spring2014_Week_1_Do_Now_Questions.docx