What do the state numbers mean?
As mentioned in lecture, there are no predefined meanings for the state numbers. It’s up to you to decide what the state numbers mean, using them to capture different contexts in which the robot finds itself, or different subtasks of its overall task. Then, based on the meanings that you assign the states, you need to write rules that take actions that make sense for various combinations of states and surroundings.
How many rules should we end up with?
There is no one solution to this problem, and different solutions will require different numbers of rules.
The assignment mentions that you could in theory solve this problem with 6 rules, but that was just meant as an optional challenge. Don’t worry if you need more than that.
Note, however, that you cannot solve it with fewer than 6 rules. If you think you have done so, it’s possible that your rules work for some starting positions but not others.
You should also make sure that you don’t have any repeat rules – two rules that will both apply for a given combination of state and surroundings. If you have any repeat rules, Picobot will give you an error message when you enter your rules.
I’m having trouble getting started on this one. Do you have any suggestions?
Here’s one possible strategy for this problem:
Start with the rules that are already there when you first enter the Picobot simulator. Run them from a number of different starting positions. (Press the Reset button after each run.)
Consider what these initial rules cause Picobot to do. What portion of the overall task of covering the room do these rules accomplish? What remains to be done?
Add new rules (possibly involving new states) that allow Picobot to finish the rest of the task – picking up from where the existing rules leave off. Don’t forget that it’s perfectly okay for Picobot to re-cover cells that it has already covered.
I’m having trouble figuring out rules that work for the maze problem. Do you have any suggestions?
First of all, make sure that you’re following the suggestions given in lecture: have a separate state number for each direction that the robot could be facing, and construct rules that are based on the “right-hand rule”.
In addition, take a look at the slides about the maze problem in the lecture notes (use the Lectures link in the navigation bar). You’ll see that it mentions that you should start by having at least three or four rules for each state.
The assignment mentions that you could in theory solve the maze problem with 8 rules, but that was just meant as an optional challenge. Don’t worry if you need more than that, and make sure that you start by constructing at least 3 or 4 rules for each state!
For Problem 3-3, do we need to put the println
statements
in a program?
No. Just put the println
statements in your ps1_partI
file.
I’m trying to print a string that includes a backslash, but I’m getting an error message. What am I doing wrong?
Don’t forget that you need to do something special to print a backslash. See the lecture notes on escape sequences (at the end of the second set of notes) and our BlockLetters example programs for a reminder of what you need to do.
For Problem 5, to what degree do we need to
eliminate code duplication? For example, if a single println
statement or a pair of println
statements appears in multiple
places, do we need to make a method for those two statements?
This is somewhat a judgement call. Typically, you wouldn’t create a
method to avoid repeating just one or two println
statements.
However, if a specific group of four or more println
statements is
repeated, it would make sense to create a separate method for those
four or more statements.
In addition, don’t forget to use methods to capture the
structure of your program. If a set of statements represents a
logical piece of the overall program, it’s a good idea to use a
separate method for them — like we did in the writeD
method in
our BlockLetters3
example program.
For Problem 5, the guidelines indicate that we should use methods both to eliminate duplication and to capture structure. When it comes to capturing structure, is it enough to have a separate method for each letter — which is the example of structure that the problem set mentions — or do we need to capture other types of structure as well?
You should capture other aspects of structure besides the individual letters. We’re being deliberately vague about what that additional structure would be, because we want you to use your own judgment here. As you do so, keep in mind what we said in lecture: that you want to break the overall task into logical subtasks, and give each subtask its own method. In this case, the overall task is printing the entire phrase, and you should start by asking yourself: What are the logical subtasks of that task? In addition, don’t forget that a subtask can itself have subtasks.
It’s worth noting that a good decomposition should produce a main method that is a concise summary of the overall task. If your main method is fairly long (i.e., more than 14 or 15 lines), then you probably want to consider methods for other types of structure.
For Problem 5, I’m not sure what you mean when you say that we should indent all lines within a method by four spaces.
It means that the statements inside a method should begin four spaces to the right of the header of the method, like this:
public static void myMethod() { System.out.println(); }
Note that the S
in System
is four spaces to the left of the p
in
public
.
Last updated on June 24, 2025.