Difference between revisions of "ExpertRobot"
(Initial commit.) |
m (→Modularization) |
||
(9 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
---- | ---- | ||
− | In order to convert a | + | In order to convert a <code>AdvancedRobot</code> into an <code>ExpertRobot</code>, replace: |
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
− | public class FirstBot extends | + | public class FirstBot extends AdvancedRobot { //... |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 21: | Line 21: | ||
== Better API == | == Better API == | ||
− | + | Basically, most of the ExpertRobot is provided via <code>IBot</code> interface. | |
− | + | <code>IBot</code> 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, <code>setAdjustGunForRobotTurn(true)</code> and the like is automatically called during the init of ExpertRobot. | |
− | + | Everything in ExpertRobot & <code>IBot</code> interface and the like is annotated with either <code>@NotNull</code> or <code>@Nullable</code>, which will force you to avoid <code>NullPointerException</code> during compilation or even writing. | |
− | + | <code>onScannedRobot</code> is replaced by <code>onScannedEnemy</code>, which gives you an <code>IEnemy</code> object for each enemy which is persistent across turns and rounds. And again, only Radians version is available. <code>IEnemy</code> 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. | |
− | + | <code>IBot</code> interface will also give you a lot of methods to predict the motion of the robot. For example, <code>getRadarTurnRate</code> 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 == | ||
Line 35: | Line 35: | ||
Modularization is done by a Strategy design pattern, with a side effect being everything is automatically persistent across rounds. | 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. | + | We strongly recommend you use/pass ExpertRobot as <code>IBot</code> 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. | + | <code>IBot</code> instance is passed to <code>onInitStrategy</code>, which is called only once in the initial of first round. |
For eample: | For eample: | ||
Line 57: | Line 57: | ||
} | } | ||
− | // | + | // DuelEye.java |
− | class | + | class DuelEye extends Module { // DuelFist & DuelWhoosh is the like |
private final @NotNull IBot bot; | private final @NotNull IBot bot; | ||
Line 68: | Line 68: | ||
@Override | @Override | ||
public void onScannedEnemy(@NotNull IEnemy e) { | public void onScannedEnemy(@NotNull IEnemy e) { | ||
− | // todo | + | // todo, e.g. |
+ | bot.setRadarTurn(e.getBearingToRadar()); // Simplest duel radar made possible by ExpertRobot | ||
} | } | ||
Line 76: | Line 77: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | In this example, anything defined and referenced in DuelStrategy is persistent across rounds. Then you can simply design everything without worrying about saving data. | + | In this example, anything defined and referenced in <code>DuelStrategy</code> 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: | + | Modularization is not forced. If you don't want yet to be modularized, simple use <code>IStrategy</code> interface, for instance: |
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Line 88: | Line 89: | ||
public void onScannedEnemy(@NotNull IEnemy e) { | public void onScannedEnemy(@NotNull IEnemy e) { | ||
// todo, e.g. | // todo, e.g. | ||
− | bot. | + | bot.setRadarTurn(e.getBearingToRadar()); // Simplest duel radar made possible by ExpertRobot |
} | } | ||
}); | }); |
Latest revision as of 19:18, 12 August 2017
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));
}
}
// DuelEye.java
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.setRadarTurn(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.setRadarTurn(e.getBearingToRadar()); // Simplest duel radar made possible by ExpertRobot
}
});
}
}