The robot lights up the blue tile, if it is standing on one The robot moves forward by jumping up one block higher, or by jumping down one or more blocks lower (if it can) The robot turns 90 degrees to its left (counterclockwise) The robot turns 90 degrees to its right (clockwise) The robot moves forward one square (if it can) Recapping the basic commands that every LightBot understands.Įarlier, we saw that LightBots know how to perform seven basic Let’s start our discussion of writing LightBot programs by (a postcondition, which describes the outcome of executing a specific On” behavior, then afterward the blue square will be lit Is indeed standing on a blue square, and then it executes its “turn light Standing on a blue square (also a precondition). The icon to light up the current square only works when the robot is Immediately in front of it is exactly one block higher or lower than Also, some methods only work under certainĬonditions: the robot can only jump (up or down) if the square Something that is assumed to be true after the method has been executed.įor example, our LightBot supports a number of methods thatĬorrespond to the icons we can use, and which we gave textual names Something that is assumed to be true before the method is invoked. Statements that are written in some programming language to describe Object can take or a task that it can perform in response to a The facts are called attributes (we’ll cover those later) and the Object can perform (the robot can move, turn left or right, and so on). Still dim? Which direction is the robot facing?), and tasks that the There are two parts to an object,įacts about the thing it represents (Is the blue square lit yet, or Objects, even though they are of the same kind.Īn object represents something, but we, as programmers, need toĭetermine what characteristics of that thing are important to the There might be multipleīricks, or multiple blue squares on a level, and these are all individual ThereĪre also blue squares that can be lighted. But there areĪlso bricks that block the robot’s path and that can be stacked. It seems obvious that the robot itself is an object. These may represent the same kind of thing. Grid positions–i.e., we always start counting from zero at the origin (topĬoncept or item that is relevant to the problem we are trying toĪ typical program works with several different objects. This means we will always used zero-based indexing when referring to The gridĪbove is 10 by 10 in size, where coordinates run from 0 up to and includingĩ. Represented in our grid and is located at the top left corner. Also notice that the origin (0, 0) is explicitly It is 4 cells horizontally to the right of the origin, and 2 cells verticallyĭown from the origin. So the highlighted cell in the grid shown above is at location (4, 2), since Though it is the opposite of what is typical in studying geometry!). We use a left-handed orientation for our axesīecause that convention is predominant in computer programming contexts (even The y axis points downward in our grid, making thisĪ left-handed Cartesian plane. The origin horizontally, and y (the second coordinate) represents the distanceįrom the origin vertically. We will use a variation of Cartesian coordinates to write any location asĪn (x, y) pair, where x (the first coordinate) represents the distance from
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |