9th Annual

Utah High School Programming Contest

Take-Home Problem

Written by Chris Alfeld and Chad Barb

Nanobots


The Story So Far

As the 21st century draws to a close, the development of new technology continues at its breakneck pace. Man has visited other planets, toasters can fly, cancer has been eliminated, and Windows can run nearly four full hours without crashing. With such phenominal advances in technology, commerce thrives in the development and application of new ideas.

Yoyodyne ("riding the high seas of high technology"(tm)) is thriving, indeed. Following their concurrent success in the biological warfare and baby formula industries, they are seeking greener pastures. Suffering from sweeping government cutbacks in baby formula subsidies, Yoyodyne saw a new opportunity with recent advances in "nanotechnogy" and was ready to pounce.

Yoyodyne engineers developed a nano-robot (which it calls a "nanobot") that can be placed on the surface of a silicon wafer before it is made into an integrated circuit. The nanobot moves around on the surface, smoothing and cleaning it as it goes.

During the design, Nanotech engineers discovered that most surfaces have a few valuable molecules scattered on them, so they revised their "bot" to collect these molecules. The nanobot works as follows:

First it is placed on the surface of a wafer at some starting point, which becomes its home base. Under the control of an on-board computer, the bot moves around the wafer, smoothing the surface and picking up valuable items. Due to size restrictions, it can only carry a small number of molecules and has a restricted fuel supply, so it must periodically return to its base and drop its cargo.

Before running out of fuel, the nanobot must return to base, where it can be retrieved to be refueled and reused. Unfortunately, a bot is permanently lost if it doesn't get back to its base before running out of fuel.

One feature of the nanobot's home base is a special flash camera that scans the surrounding area. Unfortunately, this is a one-time process, so the bot's computer must store a single image when it is placed on the surface of the wafer. This surface "map" is then used by the software to plot the nanobots course. The map is simply a 2-dimensional array of "squares", each of which represents a location on the surface of the wafer. Included on the map are the drop point (base) and locations of valuable molecules.

The map also identifies certain areas that contain sensitive components that must be avoided. Your bot may not enter one of those squares.


Problem Description

It is your job to write the software to guide a nanobot. Your goal is to provide a sequence of commands for the bot to allow it to smooth the greatest surface possible and to collect the largest number of valuable molecules with a given amount of fuel.

Your solution should, given a map and a fuel limit, produce a series of movement and pickup commands to guide the nanobot. The commands (defined in detail below) tell the nanobot to move north, south, east, or west; pick up a molecule; stop and wait to be picked up.

The bot can only carry five (5) molecules and automatically drops them when visiting the base. The bot automatically smooths a square upon entering it.

The software must prevent the bot from entering an illegal square.

Your program will receive 1 point for each square visited for the first time, plus a certain number (1-9) per valuable molecule picked up and delivered to base.

The map includes the location of the base or start point. This square never contains a valuable molecule. Every time the bot visits its base, all the molecules it is carrying are dropped and scored. If it does not end on its base (i.e., if it runs out of fuel at some other location), you will be charged 10 points (the cost of the nanobot) and any objects it is carrying at that time will not be scored.

The borders of all maps are designated as sensitive locations, so there is no way your bot can wander off of the map if your program is working properly. Note that borders may not be rectangular!!

Moving to and cleaning a square takes one fuel unit total. Picking up a molecule consumes one fuel unit.


Input

All input is from standard input (i.e., the keyboard).

Input consists of the width of the map, the height of the map, the amount of fuel, and then the map itself.

Example:

10
10
30
XXXXXXXXXX
X   3 5  X
X     4  X
X7  1    X
X   B  8 X
X        X
X 9    3 X
X   6   3X
X  4     X
XXXXXXXXXX

No map will be smaller than 3x3.

" " (space) indicates a normal (empty) square.
X indicates a sensitive square that the nanobot cannot enter.
Numbers (1-9) indicate molecules of various worth.
B indicates the starting position.


Output

All output is to standard output (i.e., the screen).

Output consists of one action per line with the actions being:

NORTH - Move North
SOUTH - Move South
EAST - Move East
WEST - Move West
TAKE - Pick up a Molecule
END - Stop

Example:

NORTH
TAKE
NORTH
EAST
EAST
TAKE
EAST
SOUTH
SOUTH
TAKE
WEST
WEST
WEST
WEST
WEST
WEST
NORTH
TAKE
SOUTH
SOUTH
SOUTH
EAST
TAKE
EAST
EAST
NORTH
NORTH
END
Input Comment Score Fuel Bin
NORTHMove north129
TAKEPick up molecule1281
NORTHMove north2271
EASTMove east3261
EASTMove east4251
TAKEPick up molecule4241 4
EASTMove east5231 4
SOUTHMove south6221 4
SOUTHMove south7211 4
TAKEPick up molecule7201 4 8
WESTMove west8191 4 8
WESTMove west9181 4 8
WESTMove west (1,2)2217
WESTMove west2316
WESTMove west2415
WESTMove west2514
NORTHMove north2613
TAKEPick up molecule26127
SOUTHMove south (2)26117
SOUTHMove south27107
SOUTHMove south2897
EASTMove East2987
TAKEPick up molecule2977 9
EASTMove East3067 9
EASTMove East3157 9
NORTHMove North3247 9
NORTHMove North (1,2)483
ENDEnd Run483

Notes:

1. Base square - dropped off all molecules
2. Previously visited square - no cleaning points.


Hints

There are several possible ways to tackle this problem. Here are a few to get you started:

Brute Force
Trying every possible solution will eventually find you the best one. Alas, with larger maps by the time it found a solution, not only would you and I not be around to appreciate it, but this planet, this solar system, and even (if certain physicists are correct) this universe will be long since gone. That having been said, this is a good technique on extremely small maps.
Random
This isn't as bad as it seems. Here you produce moves semi-randomly using various heuristics (rules) to make good guesses. The better your guesses, the better your bot will do. Of course luck also plays a big part.
Omniscient
The best solutions will take advantage of knowing the entire map. These solutions will probably do lots of calculations and make up the entire move list before printing it out.


What Else You've Got

The Simulator

We have provided C++ source code for a simulator program. This program will input a map file and a list of commands. It will figure out your score, display incorrect move commands, and potentially provide other information. This is the same program we will use to test your bots. See the README file for more information.

Sample Maps

A number of sample maps are at the bottom of this document. We will test your rover using these and other maps. Feel free to make your own maps to help test your bots.

Nanobot Shell

We have also provided a C++ version of a basic shell for your nanobot. The shell contains a main procedure that will parse the input file as well as a number of procedures to produce output. These procedures are: MoveNorth(), MoveSouth(), MoveEast(), MoveWest(), TakeMolecule(), and EndRun(). This is a good starting point but does not necessarily need to be used.


Submitting

Please submit your source code and a DOS executable via e-mail or bring a floppy disk when you come to the contest. E-mail submissions should be sent to hspc@cs.utah.edu.


Restrictions

Your submission will be run on a large number of maps. In order to keep testing times down and prevent brute force algorithms the following restrictions are imposed.

Language:
C++ or Pascal.
Maximum Run Time:
Your program will have 2 minutes to complete for most maps. On larger maps we will be more lenient.
Incorrect Output (Includes program crash):
Any program that produces bogus output or crashes will be penalized for that map (see Scoring).
I/O:
Any program that does disk or network I/O will be immediately and permanently disqualified. Your program should ONLY write to standard out and only read from standard in.
Memory:
You will have at least 8 megabytes of RAM available to your program, but not necessarily more.


Scoring

Your submission will be scored on a range of 0-200. Of these 200 points, 50 will be for code clarity, organization, and program efficiency (both memory and CPU cycles). The remaining 150 points will be based on test cases.

Clear code has meaningful variable names, indentation to show structure, comments where appropriate, and is generally easy to understand. With comments, quantity does not equal quality; please do not fill your code with useless comments. Organized code uses functions and procedures where appropriate, meaningful and intuitive data structures and, in larger projects, multiple source files and modules. Efficient code uses data structures that are sufficient for the task and algorithms that are as fast as the data allows. There is a tradeoff between speed and memory usage; if you lean heavily in one direction or the other for your program, please indicate so in a comment. Memory leaks and useless computations do not make efficient code.

Each test map will be assigned a weight. The solution that scores the top score on that map will receive the full number of points for that map; other solutions will receive a number points equal to the ratio of their score to the top score (example: on a 50 point map if the top score is 40 and your solution scores 20 then you will receive 20/40 = 1/2 the points, or 25). Solutions that crash will be penalized with a small negative score for that map. Solutions that run out of time will receive their current score at time out. The scores will be totaled, with the top total score receiving the full 150 points and the other scores receiving points in a similar manner to the map scores.

There will be at least one map that will test the limits of the problem description. For example, a 3x50 map is valid, as is a map with borders very close to the base.


Getting help

A web page that will contain bug-fixes, updates, and answers to common questions is available at the contest web page.

Please send all questions and comments to: hspc@cs.utah.edu


Sample Maps

The Open Plain:

10
10
30
XXXXXXXXXX
X   3 5  X
X     4  X
X7  1    X
X   B  8 X
X        X
X 9    3 X
X   6   3X
X  4     X
XXXXXXXXXX

Maze:

10
10
100
XXXXXXXXXX
X4   5  6X
XXXXXX XXX
X9X 4   7X
X X XXXX X
X X  3X  X
X X 2X  7X
X5  X    X
XX4XB XX3X
XXXXXXXXXX

Larger Map:

20
33
150
      XXXXXXXXXX    
      X        X    
      X        X    
XXXXXXX 3    5 XXXXX
X   2       4      X
X      4           X
X       XXX    7   X
X  3  3XXXXX       X
X       XXX        X
X1              2  X
X            3     X
X  B    3          X
X                2 X
X  2          4    X
X        1      1  X
X   XXXX           X
X   X  X     3  3  X
X   X6    1        X
X5  X  X     2     X
X   XXXX           X
X       2    3     X
X   7              X
X      XXXXXXXXXXX X
X 3    XXXXXXXXXXX X
X      XXXXXXXXXXX X
X 2           1    X
X    5       1111  X
X   XXXX    1111   X
X   1  XXXX  1     X
X 4 XXXX           X
X        2 9       X
X    3         1   X
XXXXXXXXXXXXXXXXXXXX