COSC 2010 / 2100 Data Structures

Fall 2014

Homework Assignment #1 : Magnetic Chameleon

Due: Wednesday, September 3rd, Noon CDT
Submit: Turn in your source file using the turnin command on Work is to be completed individually. Be certain to include your name in the file. You may submit multiple times, but only the last turnin will be kept. The automatic submission system will not accept work after the deadline.


The Advanced Placement GridWorld Case Study is a useful starting point for this semester's warm-up assignment.

Begin by downloading GridWorld code, as well as the Student Manual for your reference.

The Eclipse Integrated Development Environment and Java are already installed on the laboratory machines. If you would like to use another computer to do your work, it is your responsibility to ensure that the necessary software is installed.

Online resources (such as this YouTube video) can help you get started with setting up the GridWorld JAR file under Eclipse, in order to beginning running the sample projects.

For this assignment, you will be implementing your own extension of an existing GridWorld class to simulate the MagenticChameleon.

Magnetic Chameleon

GridWorld already contains a variety of Actors that can inhabit the grid: Bugs, Flowers, Rocks and Critters. This assignment will only be concerned with Rocks and Critters.

The existing ChameleonCritter example class (GridWorldCode/projects/critters/ moves randomly about the board, one square at a time, changing its color to match adjacent Actors.

Create a new Critter type, MagneticChameleon, the detects another MagneticChameleon on the grid, and attempts to move toward it on each step. If it reaches the other MagneticChameleon, it should take on the same orientation, and change its color to be halfway between its previous color and the new neighbor's color.

Unlike ChameleonCritters, MagneticChameleon should ignore any other Actors on the grid. Like ChameleonCritter, MagneticChameleon should not pass through any Rocks in its way.

If an obstacle (Rock) occupies the square that a MagneticChameleon wants to step into next, it should instead choose an unoccupied square that is closest to the direction of the other MagneticChameleon. If there is a tie between squares when it is selecting its next move location, it should default to the choice in the direction it is already going.


Points for this assignment will be awarded based upon successful completion of a battery of testcases. As you might guess, test scenerios will generally consist of placing two MagneticChameleons of various starting colors at various locations on the board, with diverse patterns of Rocks between them.

You should create many of your own testcases, (see GridWorldCode/projects/critters/ as an example,) but we will only evaluate your source file.


If you complete this assignment quickly, you might like to think about variations on the problem. Do not turn these in -- many will break TA-bot's grading testcases -- but do give them some thought:

[Revised 2014 Aug 28 23:00 DWB]