Exemplo n.º 1
0
  public String getStateSeq() {
    String seq = Action.printAction(StateSeq.get(0)) + ",";

    for (int i = 1; i < StateSeq.size() - 1; i++)
      seq += (i) + "_" + Action.printAction(StateSeq.get(i)) + ",";

    seq += Action.printAction(StateSeq.get(StateSeq.size() - 1));

    return seq;
  }
Exemplo n.º 2
0
  public void printEndWorld() {
    try {

      environment.printEnvironment();

      System.out.println("Final score: " + currScore);
      System.out.println("Last action: " + Action.printAction(lastAction));

    } catch (Exception e) {
      System.out.println("An exception was thrown: " + e);
    }
  }
Exemplo n.º 3
0
  public Simulation(Environment wumpusEnvironment, int maxSteps, boolean nonDeterministic) {

    // start the simulator
    simulationRunning = true;

    // outputWriter = outWriter;
    transferPercept = new TransferPercept(wumpusEnvironment);
    environment = wumpusEnvironment;

    agent = new Agent(environment, transferPercept, nonDeterministic);

    environment.placeAgent(agent);
    environment.printEnvironment();

    printCurrentPerceptSequence();

    StateSeq.add(lastAction);

    try {

      System.out.println("Current score: " + currScore);
      // outputWriter.write("Current score: " + currScore + "\n");

      while (simulationRunning == true && stepCounter < maxSteps) {

        System.out.println("Last action: " + Action.printAction(lastAction));
        // outputWriter.write("Last action: " + Action.printAction(lastAction) + "\n");

        System.out.println("Time step: " + stepCounter);
        // outputWriter.write("Time step: " + stepCounter + "\n");

        int action = agent.chooseAction();
        handleAction(action);

        StateSeq.add(action);

        wumpusEnvironment.placeAgent(agent);

        environment.printEnvironment();
        printCurrentPerceptSequence();

        System.out.println("Current score: " + currScore);
        // outputWriter.write("Current score: " + currScore + "\n");

        // Scanner in = new Scanner(System.in);
        // in.next();

        stepCounter += 1;

        if (stepCounter == maxSteps || simulationRunning == false) {
          System.out.println("Last action: " + Action.printAction(lastAction));
          // outputWriter.write("Last action: " + Action.printAction(lastAction) + "\n");

          System.out.println("Time step: " + stepCounter);
          // outputWriter.write("Time step: " + stepCounter + "\n");

          lastAction = Action.END_TRIAL;
          StateSeq.add(lastAction);
        }

        if (agent.getHasGold() == true) {
          System.out.println("\n" + agent.getName() + " found the GOLD!!");
          // outputWriter.write("\n" + agent.getName() + " found the GOLD!!\n");
        }
        if (agent.getIsDead() == true) {
          System.out.println("\n" + agent.getName() + " is DEAD!!");
          // outputWriter.write("\n" + agent.getName() + " is DEAD!!\n");
        }
      }

    } catch (Exception e) {
      System.out.println("An exception was thrown: " + e);
      e.printStackTrace();
    }

    printEndWorld();
  }