示例#1
0
  public static synchronized TetrisWorldResponse Execute() {
    String theRequest =
        AbstractMessage.makeMessage(
            MessageUser.kEnv.id(),
            MessageUser.kBenchmark.id(),
            EnvMessageType.kEnvCustom.id(),
            MessageValueType.kString.id(),
            "GETTETRLAISWORLD");

    String responseMessage = RLGlue.RL_env_message(theRequest);

    TetrisWorldResponse theResponse;
    try {
      theResponse = new TetrisWorldResponse(responseMessage);
    } catch (NotAnRLVizMessageException ex) {
      System.out.println("Not a valid RL Viz Message in Tetrlais World Response" + ex);
      return null;
    }

    return theResponse;
  }
示例#2
0
  public void runExperiment() {
    System.out.println("\n\nExperiment starting up!");
    String taskSpec = RLGlue.RL_init();
    System.out.println("RL_init called, the environment sent task spec: " + taskSpec);

    System.out.println("\n\n----------Sending some sample messages----------");

    /* Talk to the agent and environment a bit... */
    String responseMessage = RLGlue.RL_agent_message("what is your name?");
    System.out.println("Agent responded to \"what is your name?\" with: " + responseMessage);

    responseMessage = RLGlue.RL_agent_message("If at first you don't succeed; call it version 1.0");
    System.out.println(
        "Agent responded to \"If at first you don't succeed; call it version 1.0  \" with: "
            + responseMessage
            + "\n");

    responseMessage = RLGlue.RL_env_message("what is your name?");
    System.out.println("Environment responded to \"what is your name?\" with: " + responseMessage);
    responseMessage = RLGlue.RL_env_message("If at first you don't succeed; call it version 1.0");
    System.out.println(
        "Environment responded to \"If at first you don't succeed; call it version 1.0  \" with: "
            + responseMessage);

    System.out.println("\n\n----------Running a few episodes----------");
    for (int i = 0; i < 1; i++) runEpisode(20000);

    runEpisode(1);
    /* Remember that stepLimit of 0 means there is no limit at all! */
    // runEpisode(0);
    RLGlue.RL_cleanup();

    System.out.println("\n\n----------Stepping through an episode----------");

    // taskSpec = RLGlue.RL_init();
    // for(int i = 0; i < 2; i++) {
    // /*We could also start over and do another experiment */
    // /*We could run one step at a time instead of one episode at a time */
    // /*Start the episode */
    // Observation_action startResponse = RLGlue.RL_start();
    // int firstObservation = startResponse.o.intArray[0];
    // int firstAction = startResponse.a.intArray[0];
    // System.out.println("First observation and action were: " +
    // firstObservation + " and: " + firstAction);
    //
    // /*Run one step */
    // Reward_observation_action_terminal stepResponse = RLGlue.RL_step();
    //
    // /*Run until the episode ends*/
    // while (stepResponse.terminal != 1) {
    // stepResponse = RLGlue.RL_step();
    // if (stepResponse.terminal != 1) {
    // /*Could optionally print state,action pairs */
    // System.out.println(
    // ("(state,action)=(" +
    // stepResponse.o.intArray[0] +
    // "," +
    // stepResponse.a.intArray[0] + ")"));
    // }
    // }
    //
    // System.out.println("\n\n----------Summary----------");
    //
    // int totalSteps = RLGlue.RL_num_steps();
    // double totalReward = RLGlue.RL_return();
    // System.out.println("It ran for " + totalSteps +
    // " steps, total reward was: " + totalReward);
    // }
    // RLGlue.RL_cleanup();

  }