Robo Home | Radar | Changes | Preferences | AllPages

public void getScannedBots(){
        Vector v=getAllEvents();
        Iterator i=v.iterator();
        while(i.hasNext()) {
                ScannedRobotEvent e = (ScannedRobotEvent) i.next();
                if(e instanceof ScannedBotEvent){ onScannedRobot(e); }
Kinsen noticed that the radar might 'miss' some bots that are behind another. I haven't tested this code yet, but it should work. Just call getScannedBots?() right before the execute(); line. I'm not sure if there is a function called getAllScannedRobotEvents?(), but if there is, feel free to change the code above--Starrynte

Try using generics. Since Robocode needs Java 5 anyways.... Vector<ScannedRobotEvent> eliminates need to use instanceof. -- Aziz

Yes, I remember reading about that in some Java book...didnt think about it. thx 4 the suggestion though, code changed above --Starrynte

Well, since the getAllEvents method returns Events and not ScannedRobotEvents?, I'm not sure this line Vector<ScannedRobotEvent> v=getAllEvents(); would work. If it had ScannedRobotEvents?, you could cast them to Event, but not the other way around, right? Also, you do need the check if the object is of ScannedRobotEvent type or not, since you just want the SREs and not the other events. As written, I don't see how this is any different than what Robocode already does automatically for you with the onScannedRobotEvent method; and unless you changed the method signature of the call you're passing the SRE too, this code would end up with that method being called twice per ScannedRobotEvent. In general, I could see some usefulness in melee for collecting all the events and then dealing with them at once, of course. -- Voidious

In that case...I'll change the code back to what it was originally. I don't use generics much yet anyways...But feel free to change the code if it'll make the codesize smaller, I'm not a nano expert. --Starrynte

Robo Home | Radar | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited August 18, 2007 19:14 EST by Voidious (diff)