CMSC 341 Spring 2009
Project 1
Assigned
| Friday, January 30, 2009
|
Due
| Friday, February 13, 2009 at 11:59 PM
|
Updates
| Clarification
- IGNITE can occur in any cell even in the abscence of trees.
- WIND will blow fire from a cell to a neighboring cell along
a vector given in the command. Consider fire at cell (0,0)
and a wind vector of (-2,-2). The fire in cell (0,0) will spread
to cell (-2,-2) skipping all cells in between.
- AGE triggers the reduction in density of burning trees by 1. Fire with
zero trees to burn in a cell will go out. Trees in the absence of
fire increase in density by 1 as well as spread to neighboring cells, setting their density to 1.
- Trees with fire in their cell will not grow more dense nor will
they grow to neighboring cells.
- DOUSE extinguishes all neighbors in a radius r. This includes more
than the cardinal directions.
- AGE will trigger Fire's growth before Trees growth.
|
|
Background
The goal of this project is to have you write a Java application using
the various development tools that are required this semester: CVS,
ant, and javadoc. You will implement a simple text-based fire simulation
which will include trees, water, fire, and wind. There is
significant flexibility in how you implement the relevant classes, so think
carefully about that topic as design is part of the project grade.
Description
The simulator in which trees, water, and fire exist is an
infinitely large grid. Locations on this grid are specified by their
X and Y coordinates. The simulator's coordinate X = 0 and Y = 0, corresponds
to the center of the simulator (-X,Y would be a Northwest location).
Wind has a direction given in the form of a vector (X and Y integers).
Trees are planted at coordinates (X, Y) and with a specific density.
Cells with trees present will grow more dense in the absence of fire. Also,
Trees grow in cardinal directions populating neighboring cells that are
void of trees.
Fires have start locations (X and Y coordinate) that
are integer values. For example, there might be a "FIRE" at locations
(2, 5), (-3,7). Fire, without the presence of wind, will grow in all
cardinal directions when Trees are present in neighboring cells. If wind
has a direction, fire will only spread in that direction. Fire in any cell
will continue to burn until there are no more trees in cell.
The simulator can act the following ways:
- AGE - Increments the stage of the simulator given the current state triggering Fire and Tree to spread and grow.
- IGNITE - Creates a fire at an X,Y coordinate
- PLANT - Adds a tree at a location X,Y
- DOUSE - Extinguishes a fire at coodinates X,Y of a radius R
- WIND - Changes the wind direction of the wind vector.
Input
To test your program we will run it with a single command line
argument, which is the name of a text file containing commands as
described below. Your program must check to ensure that a single
argument is given on the command line, open the specified file
(reporting an error if that's not possible), process each command
in the file, and exit when the end of the file is reached. There may
be blank lines in the file which should be ignored.
The commands can be any of the following in any order:
- PLANT x y density
- IGNITE x y
- DOUSE x y radius
- WIND x y
- AGE
- PRINTPPM
For the all commands other than AGE, x, y, density, and radius
will be integers. The description will be a string
with no white space. All commands will be well formed so you don't
have to worry about making your command parser bullet proof. That is,
you'll never get something like "IGNITE 10" or "PLANT X Y TEN".
PRINTPPM will print the contents of all cells to an PPM image file titled "IMAGE_<AGE>.ppm". The age of these files will be the age of your simulator.
Creating a PPM File
The PPM format is one of the simplest image formats available. See the man page for
'ppm' on the university GL server for a description.
A sample PPM file is composed of the following:
P3
HEIGHT WIDTH
255
r g b . . . . . . ... r g b
.
.
.
r g b . . . . . . ... r g b
Each r g b tuple cooresponds with one pixel in the image. Mapping a cell
to a pixel is a simple process and needs to be accomplished as follows:
- The all color channels (r g b) is to be set to 0 initially.
- The red channel (r) is to be set to 255 if fire is present.
- The green channel (g) is set to 255 if trees are present.
- The absence of fire and trees from a cell is represented with r g b values of 139 69 19.
Project Notes, Hints, and Requirements
- Be sure that the main() for your program is in a file named
Proj1.java. The scripts that execute your program will assume this.
- Echo each command as it is read to System.out.
- Note that Fires and Trees share certain similarities, such
as having locations and growth methods. Think about how best to
implement the classes in light of these similarities.
- Think about encapsulating locations in a class.
- You must use Java generics if you store fires and trees in a
Java collection. For example, if you have a Vector of Fire it should
be of type Vector < Fire > rather than a Vector of Objects.
- Trees and Fires can be added to the simulator at any time in the
command file.
- Commands in the command file may be upper case, lower case, or
any combination. You should recognize Ignite and IGNITE and ignite as
the same command.
Submission
You must use CVS to check out your module in the Proj1 repository and
to check in your code. That must include an ant build.xml file and
javadoc. See
the projects
page for more information on all of these topics.
If you don't submit a project correctly, you will not get credit for it.
Why throw away all that hard work you did to write the project? Check your
submittals. Make sure they work. Do this before the due date.
Project grading is described in the
Project
Policy handout.
Cheating in any form will not be tolerated. Please re-read the Project
Policy handout for further details on honesty in doing projects for this
course.
Remember, the due date is firm. Submittals made after midnight of the due
date will not be accepted. Do not submit any files after that time.