Answer the following questions with your POGIL team:
For the robot, CAN_MOVE(forward) is true, however CAN_MOVE(right) is not true.
MOVE_FORWARD
MOVE_FORWARD
ROTATE_RIGHT
MOVE_FORWARD
MOVE_FORWARD
MOVE_FORWARD
MOVE_FORWARD
ROTATE_LEFT
MOVE_FORWARD
MOVE_FORWARD
3.)(Portfolio) Let's replace the repeated commands with a repetition control structure. The following command can be used to repeat a block of commands:
REPEAT n times
Commands
Rewrite your algorithm above using Repeat n times control structures (substituting in a
number for n) instead of repeating the MOVE_FORWARD command many times.
if(CAN_MOVE(forward) = true)
REPEAT 2 times
if(CAN_MOVE(right) = true)
ROTATE_RIGHT
if(CAN_MOVE(forward) = true)
REPEAT 4 times
if(CAN_MOVE(left) = true)
ROTATE_LEFT
if(CAN_MOVE(forward) = true)
REPEAT 2 times
4.) Can you come up with a more general algorithm to navigate a maze using IF commands and a REPEAT UNTIL GoalReached command, which tests if the robot has reached the gray square goal? Try to come up with an algorithm before looking at the algorithm on the next page.
REPEAT UNTIL GoalReached
{
if(CAN_MOVE(forward) = true)
MOVE_FORWARD
if(CAN_MOVE(right) = true)
ROTATE_RIGHT
if(CAN_MOVE(left) = true)
ROTATE_LEFT
}
Here’s a more general way to navigate a maze with the following algorithm which uses GoalReached to test if the robot has reached the gray square.
REPEAT UNTIL GoalReached
{
IF (CAN_MOVE forward)
MOVE_FORWARD
IF (CAN_MOVE left)
ROTATE_LEFT
IF (CAN_MOVE right)
ROTATE_RIGHT
}
If a maze had something with more than one true statement, such as a loop where the algorithm could turn either left or right, then the algorithm could not complete the maze because it would constantly be turning right, or whichever direction appeared first in the algorithm.
5.) (Portfolio) Write an algorithm for washing a stack of 10 items that are cups and saucers mixed together, where the rule is that the cups are washed in hot water and the saucers in cold water. Use simple commands like hot_wash and cold_wash. You may also use the control structures IF and REPEAT n times. Identify the parts of your algorithm that are examples of Sequence, Selection, and Repetition.
REPEAT 10 TIMES {
IF (is_cup)
hot_wash
ElSE
cold_wash
}
The REPEAT 10 TIMES is an example of repetition. The IF(is_cup) is selection and the code is a sequence