ExpertRobot
This page is dedicated for describing the xor.utils.ExpertRobot
ExpertRobot is a modern replacement of AdvancedRobot, specially tuned for safe and modularized development.
The goal of creating ExpertRobot is to allow you to develop a modularized modern advanced robot in minutes, with concerns only on strategies & techniques, not implementation details.
In order to convert a Robot into an ExpertRobot, replace:
public class FirstBot extends Robot { //...
with:
public class FirstBot extends ExpertRobot { //...
Better API
ExpertRobot will allow you to use only setXXX methods, and only XXXRadians version, to prevent potential mistakes. Further more, setAdjustGunForRobotTurn(true) and the like is automatically called during init.
Everything in ExpertRobot is annotated with either @NotNull or @Nullable, which will force you to avoid NullPointerException during compilation or even writing.
onScannedRobot is replaced with onScannedEnemy, which gives you an Enemy object for each enemy which is persistent across turns and rounds. And again, only Radians version is available.
Enemy class will also give you certain advanced properties at your fingertips, including position vector, velocity vector/scalar, acceleration vector/scalar and corresponding lateral/advancing version and more, which is not possible without being persistent across turns.
ExpertRobot will also give you a lot of methods to predict the motion of the robot. For example, getRadarTurnRate will give you the exact predicted turn rate of the radar relative to ground after calling setTurnRadarXXX. It's quite easy to write your own precise movement predictor with this API.
Modularization
Modularization is done by a Strategy design pattern, with a side effect being everything is automatically persistent across rounds.
We strongly recommend you use/pass ExpertRobot as IBot interface in submodules, as this will allow calls to only a recommended and safe strict subset of ExpertRobot/AdvancedRobot's API.
IBot instance is passed to onInitStrategy, which is called only once in the initial of first round.
For eample:
public class FirstBot extends ExpertRobot {
@Override
protected void onInitStrategy(@NotNull IBot bot) {
setStrategy(new DuelStrategy(bot));
}
}
// DuelStrategy.java
public class DuelStrategy extends Strategy {
public DuelStrategy(@NotNull IBot bot) {
super(new DuelWhoosh(bot), new DuelFist(bot), new DuelEye(bot));
}
}
//
class DuelWhoosh extends Module { // DuelFist & DuelEye is the like
private final @NotNull IBot bot;
DuelWhoosh(@NotNull IBot bot) {
this.bot = bot;
}
@Override
public void onScannedEnemy(@NotNull IEnemy e) {
// todo
}
// other event listeners.
}
In this example, anything defined and referenced in DuelStrategy is persistent across rounds. Then you can simply design everything without worrying about saving data.
Modularization is not forced. If you don't want yet to be modularized, simple use IStrategy interface, for instance:
public class FirstBot extends ExpertRobot {
@Override
protected void onInitStrategy(@NotNull IBot bot) {
setStrategy(new IStrategy() {
@Override
public void onScannedEnemy(@NotNull IEnemy e) {
// todo, e.g.
bot.setTurnRadar(e.getBearingToRadar()); // Simplest duel radar made possible by ExpertRobot
}
});
}
}