Pols 909 Exercise 8.1 Email me your results by noon, March 31, 2003. Begin with simpleObserverBug2 (or any more-advanced swarm simulation, such as heatbugs or sss). 1. Create a new class of agent. In addition to Bugs, I think your model needs exterminators. For sure, your Exterminator class needs a step method, but I don't have any other requirements for it. You will have to make your own way on that. Don't forget that, when you add a new class, you have to add some bookkeeping entries in the Makefile. Just figure that if Bug.o or Bug.h or Bug.m is in there, you need a parallel entry for Exterminator. 2. In our model swarm, you need to add some buildObjects stuff for the Exterminators. Before you worry about scheduling the Exterminators, you must create them. To test your creation of the bugs, in the Exterminator class put a "sayHi" method, and in the Exterminator's createEnd method put a call to its "sayHi", as in [self sayHi]. It may be that you want to create a world for the exterminators that is of the same sort as the Bugs. That is, it could be "parallel universe" of sorts where Exterminators walk around. You might take a "snapshot" of that code. Remember, to do that, you type > make clean then you step out of the directory where the code is, > cd .. then make a "tarball" (a tarred, then gzipped package) with > tar -czvf name-of-file.tar.gs name-of-directory Once that is "safe" you can go on altering files in your directory. 3. Now the hard parts. Do the best you can on this, you've got a tarball to show for your other effort, so even if you don't get this to work, I'll still be happy with you. But you have to try your best. Your task is to flesh out the meaning of existence for an Exterminator. Note the modelSwarm can answer a message "getWorld". That gives back the bug's world, not the Exterminator's world. I think you can have the Exterminator's step method include his effort to find bugs and kill them. The first thing is to find the bug. Remember the previous exercise where the bug got a list of bugs? You need a method in the Exterminator class to get the bugWorld from the ModelSwarm. You could create a method like setBugWorld:. You know what I mean? Exterminator.h has an instance var bugWorld and then Exterminator.m has -setBugWorld: aWorld { bugWorld=aWorld; return self; } Then you could put a call to that method in your model swarm. I don't think that is necessary in this case, however, because the Exterminator can just ask the modelSwarm for it, as in bugWorld=[modelSwarm getWorld]; So the Exterminator has a handle on the bugWorld, and then asks one or more spots in the world if they are occupied, and then when he finds a bug, he kills it. Finding a bug ought to be pretty easy, the essence is id aBug; //select an x and y coordinate to check for the bug x=whatever-you-want; y=whatever-you-want; //then grab a bug at x and y if there is one if ((aBug = [bugWorld getObjectAtX: x Y: y]) != nil) { //in here put your fiendishly clever antibug strategy } What to do to the bugs is, of course, up to you. One possibility is to kill them outright. I think the best way to do that is to write a method in the model swarm like -killBug: (id)bugID { [bugID eraseYourselfFromWorld]; [bugList remove: bugID]; [bugID drop]; } You can implement a reaperQueue, as in swarm sugar scape (sss), but, I don't think it is absolutely required here. Maybe it is, I don't know for sure. The Bug has to have a method eraseYourselfFromWorld, can't you see? All that method has to do is this: [world putObject: nil atX: xPos Y: yPos]; 4. You may need to put in printf statements here and there so you can monitor the progress of the simulation. 5. I think, if things work correctly, there should be no absolute need for changes in the ObserverSwarm files. The bugs should just disappear from the raster. However, you might get curious to find out if you can get a display of the Exterminators. You can create a new ZoomRaster, and make it work just like the bug raster does. I don't see anything too tough there, but you may need to ask me for help. Dont forget, if you create a Exterminator raster, you need to schedule it too. Make a tarball of your effort after step 2. If that tarball represents a working program, send it to me in a mail attachment. If that tarball is just effort--it does not compile/run--then mail it to me. In addition, mail me the tarball from your work through part 2.