BYU logo 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 in a room, with a passageway to a car

Bit paints the room blue and then leaves:

the room is blue and bit is at his car

The starter code is in paint_and_exit.py.

Advice:

  • 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:

Bit in a garden with some blue 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:

all the rocks are removed

Your solution should also solve the second starting world:

Bit in a garden with some blue rocks

The starter code is in remove_rocks.py.

Advice:

  • 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 in a world with some black squares

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:

The path that Bit takes, marked with green and blue squares

There is a second world that looks like this:

Bit in a world with some black squares

The second ending world looks like this:

The path that Bit takes, marked with green and blue squares

The starter code is in scurry.py.

Advice:

  • Be sure to decompose this problem into multiple functions. You probably need at least one additional function.
  • Be sure you have the right stopping condition.
  • Think carefully about the additional conditions you need.

Grading

ActivityPoints
paint_and_exit.py6
remove_rocks.py6
scurry.py8