HeinousAlienLocator
class that uses this sensor to
determine if a particular alien is anywhere on campus and, if so, where
it is.
Your submission must be consistent with these documents.
HeinousAlienLocator
, you might want to play around a little
bit. For example, here's a HeinousAlienLocator
that
scans the whole area and then scans some cells around I81. (Note:
As it turns out, this algorithm will find Omastar.)
import java.awt.Point; public class HeinousAlienLocator { private Sensor sensor; public HeinousAlienLocator(Sensor sensor) { this.sensor = sensor; } public Point search(int x, int y, int width) { int resultOfScan; Point resultOfSearch; resultOfSearch = null; // Check the whole area resultOfScan = sensor.scan(x, y, width); if (resultOfScan < 0) // The alien isn't in the area { resultOfSearch = null; } else // The alien is in the area so let's search some more { // Try some cells around I81 for (int xx=300; xx<340; xx++) { resultOfScan = sensor.scan(xx, 323, 1); if (resultOfScan == 1) { resultOfSearch = new Point(xx, 323); break; } } } return resultOfSearch; } }
Copyright 2011