Robot karel windows 7
And because Karel encourages imagination and creativity, you can have quite a lot of fun along the way. The intersection of a row and a column is called a corner. Karel can only be positioned on corners and must be facing one of the four standard compass directions north, south, east, west. A sample Karel world is shown below. Here Karel is located at the corner of 1st row and 1st column, facing east.
The object in front of Karel is a beeper. The solid lines in the diagram are walls. Karel cannot walk through walls and must instead go around them. When Karel is shipped from the factory, it responds to a very small set of commands.
Lets try out the commands. Use the buttons bellow to get the "world" to match the "goal":. Here is what each command does: Command Description move Asks Karel to move forward one block. Karel cannot respond to a move command if there is a wall blocking its way. The empty pair of parentheses that appears in each of these commands is part of the common syntax shared by Karel and Python and is used to specify the invocation of the command. These parentheses will therefore be empty in standard Karel programs, but you must remember to include them nonetheless.
If Karel tries to do something illegal, such as moving through a wall or picking up a nonexistent beeper, an error condition occurs. Instead, you need to incorporate them into a Karel program. You will have a chance to see a few simple Karel programs in Chapter 2! Next Chapter. I use OS 9.
The materials here should work on earlier versions if you have Java running on your system. If you download this see the link above , I'd like to know about it so I can keep track of how many users there might be.
Since I don't track your usage here, the only way I can know is if you send me email. Please do, at berginf pace. If you are an instructor, you may distribute these materials to your students for use with the manuscript. If you are a student, you may download a copy for your own use.
If you are a student, I won't be able to help you with assignments from your instructor. If you need help, ask your instructor after you think really hard about the problem. The instructions apply, however.
On October 3, , I started a Change History for the simulator. Write a main class something like KarelMain.
Make sure that the class is in package kareltherobot. You should probably implement the Directions interface also. If you use an IDE to develop, make sure you include the jar file and depending on your IDE get it into the classpath also. The above command is for Windows, of course. The Karel world is no longer visible by default. I suggest that you do this from a static initializer in your main class file. In fact, this is also a good place from which to open a world file.
If you do it before settiing the world to be visible, your world will first appear with all walls and beepers in place. On many systems, double clicking on the KarelJRobot.
See Caveats below for an assist in doing something similar on systems that don't support this. Pick up a tool in the tools button panel. The name of the current tool is highlited. Click where you want to place an item controlled by that tool. For beepers click near an intersection when using the beeper tool. For walls, click across streets for vertical walls and across avenues for horizontal walls when using the corresponding tool.
To put more than one beeper on a corner, click more than once with the beeper tool active. To lower the number of beepers on a corner, control click the corner with the beeper tool. To put an infinite number of beepers on a corner, control-click with the beeper tool when there are none on the corner. To remove a wall from across a street, control click the wall segment with the appropriate wall tool. To change the number of streets or avenues in the world, enter an integer into the corresponding text field and hit enter.
Note that this doesn't restrict the world in any way. It just determines how much of it is drawn with street and avenues. Save when you like. I've used an extension kwld here, but there is nothing special about it.
It is neither assumed or automatically appended. The Clear World button will remove all elements from the world. Be careful, there is no UNDO here. Quit the world builder by closing either of its windows. If your world has been modified since the last Save you will be prompted to save it again. If you use an IDE, make a separate project for this and include the jar file.
Make kareltherobot. WorldBuilder the main file for the project. In Codewarrior on the Macintosh at least you need to set the output to be a class folder rather than a jar file, since the main is in the existing jar file, and not in any code of your own. After you build this class folder will be empty.
Since it is written in Java 1. World builder shows the position of the mouse in street,avenue coordinates if you have selected any tool. If the current tool is the Beeper tool, it shows the nearest corner where the beeper will be placed if you click. If the current tool is the Horizontal Wall tool, it shows where the corner below the wall that will be placed. If the current tool is the Vertical Wall tool it shows the corner to the left of the wall that will be placed.
NEW Here is a complete set of worlds for the book -- zip format with dos endlines. Include a statement in your robot program to open it. Include this at the beginning of your main task block.
The format is compatible with that of the older simulator. However, there is no need to use the older version as this is an extension. Lines that do not start with a keyword for the builder are ignored. Elements can appear in any order. They are NOT case sensitive. The first line KarelWorld is not a keyword, but it might be in the future.
It might also contain a version number eventually. It is ignored when reading now, but written when you save a world. The following gives the meaning of the current keywords. This is not expected to change. The world builder writes out a separate wall command for each segment of a wall one block long. If you do it by hand, you can combine them.
If you create a world in a Robot program using the programming interface in this version or the previous one and save it, it will be consistent with the world builder files.
Instructions for some World features, how to use a task, and running robots in threads. See the JavaDoc for more on World capabilities. The JavaDoc files are now in the distribution.
If you don't have the benefit of an IDE and need to compile your programs from the command line, you need to do two things generally. First is that you need the -d. Second you need the -classpath option. Probably it should be for Windows -classpath. So your full command would be.
It is case sensitive. On unix systems the single semicolon should be replaced by a colon. In the world builder: On the Macintosh OS 9 there is a drawing update bug. If the main window gets out of sync, just resize it. On OS X, if you quit this version with Command-Q or by selectiing Quit from the Apple menu, you won't get the save menu for a changed file that you would if you click the close box for one of the windows. The same seems to be true of a double clickable jar on OS X, for example.
In the world builder, the control dialog for the simulator which is useless here isn't always hidden. The effect is sporadic. It seems to work on a PC. If not, there is a batch file that you can use to do this. Put it in the same directory as the jar file and double click it to run the world builder.
This file is in the distribution zip in a Windows directory. If you have trouble, create a file named WorldBuilder. It is written in Java 1. The button highliting doesn't happen though. If you work on a Macintosh under OS 9, there is an application shell for the world builder.
It is in the Macintosh folder in the distribution zip. Put it in the same folder as the KarelJRobot. The Macintosh OS 9 world builder application shell and the Windows batch file mentioned just above are now in the zip in separate folders. Move the file appropriate to your system to your working directory the one that contains KarelJRobot. You can then just double click to run the world builder. On Mac OS X, double clicking the jar itself should work. It may also on Linux, but I have no way to test it.
The simulator now shows the mouse's position in the main window as the closest corner. The coordinates are in the control dialog. Note that as before the control dialog has a close box, but it is inactive. The dialog may be resized, however, for fine grained speed control. Robots are now shown slightly differently after they turnOff. They have a greyed out look. There are two new messages understood by UrRobots and hence by all robots. You can make a robot invisible at the next drawing of the screen by sending it a message like.
You can make it visible again with setVisible true. You can also ask an UrRobot if it is currently visible with the predicate isVisible. Note especially that predicates are only introduced for Robots Chapter 5 in the text.
0コメント