CS 102 (Spring 2003)
Lab 4c: Mazes (Part c)

Author: Ron K. Cytron
Lab Assigned Design Due
(In class)
10 AM
(In Lab)
(In Lab)
Lab Due
(In lab)
25 Feb 26 Feb 19 Mar 19 Mar


You are surrounded by interconnnection networks: the Internet, the network serving your dorm room, the POTS (plain old telephone service) network. In this lab, you create a network structure that could be used to route message between a set of nodes. The network you create is in fact an unrooted tree.

Another view of this assignment: In this lab you create a maze that could be used to have a mouse find some tasty cheese food.

OK, I confess: the true nature of this lab is to give you experience with threads, concurrency, visualizations, and components. You will explore the nature and causes of deadlock as well as the deadlock avoidance. But the maze and network anaologies are accurate.


By the end of this lab, you should

Before starting:

Particulars, Maze Construction

A new building has been constructed on our campus. This building is unusual, in that its inhabitants will consist of robots without eyes. This building contains a rectangular grid of square rooms. Each room has four walls, and each wall is equipped with a door for exit from the room. When the doors of two adjecent rooms are opened, a hallway is formed, so people can travel freely between the two rooms.

However, this building has a strange property: if ever a set of rooms is interconnected to form a loop, the world as we know it would cease to exist. (How's that for a strict building code?) Actually, a robot navigates the building by always keeping one of its "hands" in contact with a wall surface.


then a robot can start at any room and eventually reach each room in the building by maintaining contact with a wall surface.

Also, there is exactly one sequence of hallways between any two rooms. This yields a unique way to direct somebody (or an Internet packet) from one room to another.

When the building was constructed, the rooms were placed in the buildings with their doors closed. Then, a painter was airdropped into each room to paint the room.

Currently, there is a painter inside each room. Strangely, each painter is busily busily painting his or her room a unique color. Unexpectedly, the roof arrives and is placed on the building. Consequently, with all doors closed, each painter is trapped inside his or her room, as shown below

Each solid square is a room. You can see the outline of the potential hallways, but in the picture, all doors are closed.

The picture shows there are 15 sets, with one room in each set.

Suddenly, each painter is overcome by an urge to escape and paint the entire set of rooms his or her unique color. Frustratingly, each painter is trapped and does not know which doors to open, given the strange properties of this building. (You know: if ever a set of rooms is interconnected to form a loop, the world as we know it would cease to exist.) Randomly, painters in adjacent rooms call to each other to see if the doors between them should be opened. How do they decide if it is safe?

If the two rooms are currently in different sets (painted different colors), then the doors between them can and should be opened. Otherwise, the doors must not be opened because a loop would be formed.
When the doors are opened, the two painters are necessarily in rooms of different colors.
Above, you see two rooms with their doors closed. The potential hallways are shown in outline form. Above, the left room has opened its East door and the right room has opened its West door. As a result, a hallway is formed and people can move between the two rooms.

To save time, the painters agree to paint the smaller set of rooms the color of the larger set. If both sets contain the same number of rooms, the painters arm-wrestle or throw a fair coin to see who wins.

The process of opening doors and painting rooms continues.

This picture shows an intermediate point in the computation.

Here, there are three sets of rooms: light-green, black, and dark-green.

One step later, two rooms in the bottom row are adjoined.

As a result, two of the sets have been merged. Because the dark-green rooms outnumber the black ones, the black rooms are painted dark-green as they are merged into the same set.

The process of opening doors continues until all the rooms are interconnected and painted the same color. At this point, all rooms are in the same set.

The computation is finished:
  • There is one path between each pair of rooms.
  • A robot traverse the maze by keeping one "hand" on a wall.


What to turn in:

  1. Complete a code cover sheet.
  2. Provide a printout of any files you have modified.

Last modified 00:40:27 CST 17 February 2003 by Ron K. Cytron