コード例 #1
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(super.toString()).append("\n");
   for (Action a : getActions()) {
     sb.append("  ").append(a.toString(false)).append("\n");
   }
   for (Property p : getProperties()) {
     sb.append("  ").append(p.toString(false)).append("\n");
   }
   return sb.toString();
 }
コード例 #2
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Get objects from ScriptEntry
    dItem item = (dItem) scriptEntry.getObject("item");
    Duration duration = (Duration) scriptEntry.getObject("duration");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Action action = (Action) scriptEntry.getObject("action");

    // Report to dB
    dB.report(
        getName(),
        aH.debugObj("Action", action.toString())
            + item.debug()
            + (duration != null ? duration.debug() : "")
            + location.debug());

    if (action == Action.PLACE) {

      int ticks = Integer.MAX_VALUE;
      if (duration != null) ticks = duration.getTicksAsInt();

      // Display the item
      if (displayed.containsKey(location.dScriptArgValue())) {
        displayed.get(location.dScriptArgValue()).remove();
        displayed.remove(location.dScriptArgValue());
      }

      // Remember the item entity
      displayed.put(
          location.dScriptArgValue(),
          location
              .getBlock()
              .getLocation()
              .add(0, 1, 0)
              .getWorld()
              .dropItem(location, item.getItemStack()));
      displayed.get(location.dScriptArgValue()).setPickupDelay(Integer.MAX_VALUE);
      displayed.get(location.dScriptArgValue()).setTicksLived(ticks);
    }

    // Remove the item
    else if (action == Action.REMOVE) {
      if (displayed.containsKey(location.dScriptArgValue())) {
        displayed.get(location.dScriptArgValue()).remove();
        displayed.remove(location.dScriptArgValue());
      }
    }
  }
コード例 #3
0
  /** Perform a single action on the store and uses the callback to indicate of the result. */
  public void performActions(final Action action, final Callback<Void> callback) {
    logger.d(String.format("Performing Single Action: %s", action.toString()));

    mExecutor.execute(
        new Runnable() {

          @Override
          public void run() {
            Operation operation = action.getOperation();
            Voicemail message = action.getVoicemail();

            if (performSingleAction(operation, message)) {
              logger.d("< Action Succeeded >");
              callback.onSuccess(null);
            } else {
              logger.d("< Action Failed >");
              callback.onFailure(new VvmStoreException(operation, message));
            }
          }
        });
  }
コード例 #4
0
ファイル: Client.java プロジェクト: erikvanegmond/CI2015Car
  /**
   * @param args is used to define all the options of the client. <port:N> is used to specify the
   *     port for the connection (default is 3001) <host:ADDRESS> is used to specify the address of
   *     the host where the server is running (default is localhost) <id:ClientID> is used to
   *     specify the ID of the client sent to the server (default is championship2009) <verbose:on>
   *     is used to set verbose mode on (default is off) <maxEpisodes:N> is used to set the number
   *     of episodes (default is 1) <maxSteps:N> is used to set the max number of steps for each
   *     episode (0 is default value, that means unlimited number of steps) <stage:N> is used to set
   *     the current stage: 0 is WARMUP, 1 is QUALIFYING, 2 is RACE, others value means UNKNOWN
   *     (default is UNKNOWN) <trackName:name> is used to set the name of current track
   */
  public static void main(String[] args) {
    parseParameters(args);
    SocketHandler mySocket = new SocketHandler(host, port, verbose);
    String inMsg;

    Controller driver = load(args[0]);
    driver.setStage(stage);
    driver.setTrackName(trackName);

    /* Build init string */
    float[] angles = driver.initAngles();
    String initStr = clientId + "(init";
    for (int i = 0; i < angles.length; i++) {
      initStr = initStr + " " + angles[i];
    }
    initStr = initStr + ")";

    long curEpisode = 0;
    boolean shutdownOccurred = false;
    do {

      /*
       * Client identification
       */

      do {
        mySocket.send(initStr);
        inMsg = mySocket.receive(UDP_TIMEOUT);
      } while (inMsg == null || inMsg.indexOf("***identified***") < 0);

      /*
       * Start to drive
       */
      long currStep = 0;
      while (true) {
        /*
         * Receives from TORCS the game state
         */
        inMsg = mySocket.receive(UDP_TIMEOUT);

        if (inMsg != null) {

          /*
           * Check if race is ended (shutdown)
           */
          if (inMsg.indexOf("***shutdown***") >= 0) {
            shutdownOccurred = true;
            System.out.println("Server shutdown!");
            break;
          }

          /*
           * Check if race is restarted
           */
          if (inMsg.indexOf("***restart***") >= 0) {
            driver.reset();
            if (verbose) System.out.println("Server restarting!");
            break;
          }

          Action action = new Action();
          if (currStep < maxSteps || maxSteps == 0)
            action = driver.control(new MessageBasedSensorModel(inMsg));
          else action.restartRace = true;

          currStep++;
          mySocket.send(action.toString());
        } else System.out.println("Server did not respond within the timeout");
      }

    } while (++curEpisode < maxEpisodes && !shutdownOccurred);

    /*
     * Shutdown the controller
     */
    driver.shutdown();
    mySocket.close();
    System.out.println("Client shutdown.");
    System.out.println("Bye, bye!");
  }
コード例 #5
0
 private static final String getActionForIntent(Context context, Action action) {
   return context.getPackageName() + "." + action.toString();
 }
コード例 #6
0
 @Override
 public String toString() {
   super.toString();
   return "ActionDeplacement [x=" + x + ", y=" + y + ", personnageName=" + personnageName + "]";
 }