package tango.haiku; import robocode.*; public class HaikuTracker extends AdvancedRobot { String TargetName; public void run() { setTurnGunRight(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { if (TargetName==null || TargetName==e.getName()) { TargetName=e.getName(); turnRight(e.getBearing()); ahead(e.getDistance()-20); fire(3); } } }
Actually you couldn't, try. At best you might be able to squeeze a nano down to Haiku size, and I certainly have been unable to do that with a nano as complex as NanoSatan. -- Kuuran
Ok, so maybe it was an exageration, but i still don't like it. I've just had an idea for reducing the lines, so hang on. -- Tango
Here's my best shot at it:
package tango.haiku; import robocode.*; public class HaikuTracker extends AdvancedRobot { String TargetName; public void run() { setTurnGunRight(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { turnRight(((TargetName = (TargetName == null || TargetName == e.getName()) ? e.getName() : TargetName) == e.getName()) ? e.getBearing() : 0); ahead((TargetName == e.getName()) ? ((fireBullet(3) == null)?1:1) * e.getDistance() - 20 : 0); } }-- Kuuran
That's pretty much what i did, except mine doesn't fire, because i don't like your method, so i changed e.getDistance()-20 to +20, so it rams, rather than fire. -- Tango
package tango.haiku; import robocode.*; public class HaikuTracker extends AdvancedRobot { String TargetName; public void run() { setTurnGunRight(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { if (TargetName==null) TargetName=e.getName(); turnRight(((TargetName==e.getName())?1:0)*e.getBearing()); ahead(((TargetName==e.getName())?1:0)*e.getDistance()+20); } }
OK, so it's not pretty much what i did anymore, because you just changed it... i'm not sure if i call that cheating... -- Tango
I have a further change as well..
package tango.haiku; import robocode.*; public class HaikuTracker extends AdvancedRobot { String TargetName; public void run() { setTurnGunRight(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { turnRight(((TargetName = (TargetName == null || TargetName == e.getName()) ? e.getName() : TargetName) == e.getName()) ? e.getBearing() : 0); ahead((TargetName == e.getName()) ? ((fireBullet(3) == null)?1:1) * e.getDistance() - 20 : 0); } public void onRobotDeath(RobotDeathEvent e) { TargetName = (TargetName == e.getName()) ? null : TargetName; } }Now it will actually acquire a next target once the current dies. -- Kuuran
I wanted to do that, but didn't have enough lines. I still don't like your methods. I'm going to suggest a vote on whether they are in the spirit of HaikuBots. -- Tango
If you check tobe's website there's also another version of HaikuTracker which simply rotates until it sees a bot in front of it, then moves forward, rotates again, etc. -- Kuuran
Does it work in melee? ie. does it remember names? -- Tango
No, here is the code:
/** * HaikuTracker - a robot poem by Michael Dorgan */ public class HaikuTracker extends AdvancedRobot { public void run() { turnLeft(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { setAhead(e.getDistance()-140); setTurnLeft(getTurnRemaining()); setFire(3); } }-- Kuuran
Ours are better. I don't understand the set commands. Won't that bot go in a wierd curve, rather than towards the enemy? :-/ -- Tango
I was wondering about that myself, it does. However that's not neccesarily a bad thing, you still end up in the same place, and curves are harder to hit, plus it can move continually to most recently seen position, rather than go to a waypoint and then move to the next seen position in increments. The big fault I see is that it has to turn the robot around almost 360 if the opponent moves just a bit to it's right side. -- Kuuran
I don't think you do end up in the same place. You won't even end up facing in the right direction. A curve is longer than a straight line, so the distance will be wrong, and because some of it's movement would be in the wrong direction at the beginning of the turn, it would end up with the correct heading, but the desired heading would have changed because it is in the wrong place. -- Tango
But it's correcting and recalculating every tick. The desired heading doesn't change either, you end up a bit closer because of the circular route, but it's like taking a string with fixed ends and pulling on the middle, the ends just pull closer to each other, their relative orientation remains the same. -- Kuuran
How about you watch it, rather than speculating whether or not it works? -- Kawigi
I already have, I think at this point it's a matter of debating code efficiency, which is hard to judge from performance alone. -- Kuuran