Computer Science

To start this assignment, download this zip file.

# Homework 2b — Conditions

## 1. Paint and exit

For this problem, Bit wants to paint the room blue and then go to its green car. There is only one starting world:

Bit paints the room blue and then leaves:

The starter code is in `paint_and_exit.py`.

• Be sure to decompose this problem into multiple functions. You probably need two.
• Write one function at a time and test it to be sure it works.
• For each function, think about the stopping condition and any other conditions the function needs.
• Use the event stream pattern. For example, instead of thinking of painting the room as doing four walls, think of how to do this using an event stream. Likewise, don’t think of moving to the car as two steps, but one step with an event stream.

## 2. Remove Rocks

For this problem, Bit is in a garden and wants to remove rocks:

• The rocks are shown in blue.
• The green blocks mark the beginning and end of the strawberry patch. Only the rocks inside the patch should be removed.
• Do not remove the strawberries, which are the red squares!

After removing the rocks, the world should look like this:

Your solution should also solve the second starting world:

The starter code is in `remove_rocks.py`.

• Be sure to decompose this problem into multiple functions. You probably need three.
• Write one function at a time and test it to be sure it works.
• For each function, think about the stopping condition and any other conditions the function needs.
• When removing rocks, use the event stream pattern.

## 3. Scurry

For this problem, Bit is running around in a world like this:

Bit follows these rules:

• Bit moves until the front, left, and right are all blocked.
• Bit prefers to move straight.
• If the front is blocked, Bit turns in the direction that is open.
• As Bit moves, it paints empty squares green and green squares blue.

If Bit follows these rules for the world above, the ending world will look like this:

There is a second world that looks like this:

The second ending world looks like this:

The starter code is in `scurry.py`.

`paint_and_exit.py`6
`remove_rocks.py`6
`scurry.py`8
Manual grading will focus on decomposition, functions that return a boolean, and use of the logical operators `and` and `or`.