[snip]
> i'm relatively new to both java and robocode.
> when i build a robot i extend one of JuniorRobot, Robot or
> AdvancedRobot. Then i overwrite the run() method to run my own code.
>
> but can i write a robot with some basic behavior and extend that
> instead of robot?
Yes, a lot of robots are developed that way. You could make your own
robot based on e.g. the AdvancedRobot, and then create your own base
class on top on this, e.g. one that has a good scanning strategy.
Next you could extend this one for making variants or complete robots.
With Robocode 1.6.0 and newer versions, you can also create your own
robot class bases on the core robocode.robotinterfaces backage, which
is a more "raw" way to create new robot classes. The JuniorRobot,
Robot, AdvancedRobot, TeamRobot are all based on these interfaces, so
you could make your own robot type if you want to, but it still has
to follow the common rules and limitations provided with the robot
interfaces.
> and can i overwrite methods like fire() or ahead()?
Yes, but you must call super's methods first. Otherwise it will not
work. E.g.
public void fire(double power) {
if (someCondition) {
power = 1;
}
super.fire(power);
}
I do not recommend overriding the API methods. It makes it hard to
tell what is going on inside your robot. I think it better that you
make your own methods like:
public void doFire(double power) {
if (someCondition) {
power = 1;
}
fire(power);
}
> if so, can i copy the source code from the robot class and edit it?
> imagin a fire() method that does not check for gun heat and does
not
> decreas my life... rapidfire robot!
You can make your own Robot class by copying the source from the
Robot class. As I mentioned, this is using the
robocode.robotinterfaces:
http://robocode.sourceforge.net/docs/robocode/robocode/robotinterfaces/package-summary.html
For example, you could implement your own robot type that is
inherited from robocode.robotinterfaces.IBasicRobot, and then use the
getPeer(), which will return a
robocode.robotinterfaces.peer.IBasicRobotPeer which you can use for
telling your robot what to do, and also read out data etc. The Robot
class does this.
But it still has to obey the rules in Robocode, and this is protected
by the peers (the ones in robocode.robotinterfaces.peer).
- Flemming