Difference between revisions of "ExpertRobot"

From Robowiki
Jump to navigation Jump to search
m (<code>)
 
(6 intermediate revisions by the same user not shown)
Line 21: Line 21:
 
== Better API ==  
 
== Better API ==  
  
ExpertRobot will allow you to use only setXXX methods, and only XXXRadians version, to prevent potential mistakes. Further more, <code>setAdjustGunForRobotTurn(true)</code> and the like is automatically called during init.  
+
Basically, most of the ExpertRobot is provided via <code>IBot</code> interface.  
  
Everything in ExpertRobot 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>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.  
  
<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.
+
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>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>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.
  
ExpertRobot 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.
+
<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 57: Line 57:
 
}
 
}
  
//
+
// DuelEye.java
  
class DuelWhoosh extends Module { // DuelFist & DuelEye is the like
+
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 88: Line 89:
 
       public void onScannedEnemy(@NotNull IEnemy e) {
 
       public void onScannedEnemy(@NotNull IEnemy e) {
 
         // todo, e.g.
 
         // todo, e.g.
         bot.setTurnRadar(e.getBearingToRadar()); // Simplest duel radar made possible by ExpertRobot
+
         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
      }
    });
  }
}