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 AdvancedRobot
into an ExpertRobot
, replace:
public class FirstBot extends AdvancedRobot { //...
with:
public class FirstBot extends ExpertRobot { //...
Better API
Basically, most of the ExpertRobot is provided via IBot
interface.
IBot
interface will allow you to use only setXXX methods for actions, and only XXXRadians version for everything that involved angle, to prevent potential mistakes. Further more, setAdjustGunForRobotTurn(true)
and the like is automatically called during the init of ExpertRobot.
Everything in ExpertRobot & IBot
interface and the like is annotated with either @NotNull
or @Nullable
, which will force you to avoid NullPointerException
during compilation or even writing.
onScannedRobot
is replaced by onScannedEnemy
, which gives you an IEnemy
object for each enemy which is persistent across turns and rounds. And again, only Radians version is available. IEnemy
interface 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.
IBot
interface 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 DuelEye extends Module { // DuelFist & DuelWhoosh is the like
private final @NotNull IBot bot;
DuelWhoosh(@NotNull IBot bot) {
this.bot = bot;
}
@Override
public void onScannedEnemy(@NotNull IEnemy e) {
// todo, e.g.
bot.setTurnRadar(e.getBearingToRadar()); // Simplest duel radar made possible by ExpertRobot
}
// 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
}
});
}
}