Ejemplo n.º 1
1
  /**
   * Yields all percepts that are currently available.
   *
   * @return a list of percepts or an empty-list if perceiving failed
   */
  protected Collection<Percept> getAllPercepts() {

    Map<String, Collection<Percept>> percepts = null;
    while (percepts == null) {
      try {
        percepts = ei.getAllPercepts(getName());
      } catch (PerceiveException e) {
      } catch (NoEnvironmentException e) {
      }
    }
    Collection<Percept> ret = new LinkedList<Percept>();
    for (Collection<Percept> ps : percepts.values()) {
      ret.addAll(ps);
    }

    // sweep mental attitudes if there has been a restart
    // TODO maybe use simulation-id
    int step = -1;
    for (Percept p : ret) {
      if (p.getName().equals("step")) {
        step = new Integer(p.getParameters().get(0).toProlog()).intValue();
        break;
      }
    }
    if (step != -1 && step < oldStep) {
      println("sweeping mental attitudes");
      beliefs.clear();
      goals.clear();
    }
    if (step != -1) oldStep = step;

    return ret;
  }
Ejemplo n.º 2
0
  @Override
  public Action step() {

    for (Percept p : getAllPercepts()) {
      if (p.getName().equalsIgnoreCase("auctionJob")) {}

      if (p.getName().equalsIgnoreCase("pricedJob")) {
        //				System.out.println(p.toXML());
        List<Parameter> list = p.getParameters();
        Parameter id = list.get(0);
        Parameter storage = list.get(1);
        Parameter begin = list.get(2);
        Parameter end = list.get(3);
        Parameter reward = list.get(4);
        Parameter itemName = list.get(5);
        //				Parameter amount = list.get(6);
        //				if(list.get(7) != null){
        //					Parameter delivered = list.get(7);
        //				}
        System.out.println("Storage : " + storage.toString());
        return CityUtil.action("goto", "facility=" + storage.toString());
      }

      //			for(Parameter param : list){
      //				System.out.println(param.toString());
      //				System.out.println("-----------------------------------");
      //			}
    }

    return CityUtil.action("goto", "facility=shop1");
  }
Ejemplo n.º 3
0
  public void run() {
    String selectedEntity = (String) entityCombo.getSelectedItem();

    perceptModel.clear();
    final List<Percept> storedPercepts = env.getStoredPercepts(selectedEntity);
    if (storedPercepts != null) {
      for (Percept p : storedPercepts) {
        perceptModel.addElement(p.toProlog());
      }
    }

    revalidate();
    repaint();
  }
Ejemplo n.º 4
0
 @Override
 public void handlePercept(Percept arg0) {
   // TODO handle percepts if necessary
   if (arg0.getName().equalsIgnoreCase("simStart")) {}
 }
  @Override
  public Action execute(TargaryenAgent agent) {
    // Alles vergessen was letzte Runde sichtbar war
    agent.removeBeliefs("visibleEntity");

    // Percepts einarbeiten
    for (Percept p : agent.retrieveAllPercepts()) {
      if (p.getName().equals("position")) {
        agent.removeBeliefs("position", "", agent.getName());
        LogicBelief newBelief =
            new LogicBelief(
                "position", p.getParameters().get(0).toString(), agent.getName(), agent.getRole());
        agent.addBelief(newBelief);
        agent.broadcastBelief(newBelief);
        if (agent.getAllBeliefs("vertex", p.getParameters().getFirst().toString()).isEmpty()) {
          agent.addBelief(new LogicBelief("vertex", p.getParameters().getFirst().toString(), "-1"));
        }
      } else if (p.getName().equals("visibleEdge")) {
        if (agent
                .getAllBeliefs(
                    "edge",
                    p.getParameters().getFirst().toString(),
                    p.getParameters().getLast().toString())
                .isEmpty()
            && agent
                .getAllBeliefs(
                    "edge",
                    p.getParameters().getLast().toString(),
                    p.getParameters().getFirst().toString())
                .isEmpty()) {
          LogicBelief newBelief =
              new LogicBelief(
                  "edge",
                  p.getParameters().get(0).toString(),
                  p.getParameters().get(1).toString(),
                  "11");
          agent.addBelief(newBelief);
          // broadcastBelief(newBelief);
        }
      } else if (p.getName().equals("money")) {
        agent.removeBeliefs("money");
        agent.addBelief(new LogicBelief("money", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("steps")) {
        agent.removeBeliefs("totalSteps");
        agent.addBelief(new LogicBelief("totalSteps", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("edges")) {
        agent.removeBeliefs("totalEdges");
        agent.addBelief(new LogicBelief("totalEdges", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("vertices")) {
        agent.removeBeliefs("totalVertices");
        agent.addBelief(new LogicBelief("totalVertices", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("strength")) {
        agent.removeBeliefs("strength");
        agent.addBelief(new LogicBelief("strength", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("health")) {
        agent.removeBeliefs("health");
        agent.addBelief(new LogicBelief("health", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("maxHealth")) {
        agent.removeBeliefs("maxHealth");
        agent.addBelief(new LogicBelief("maxHealth", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("energy")) {
        agent.removeBeliefs("energy");
        agent.addBelief(new LogicBelief("energy", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("maxEnergy")) {
        agent.removeBeliefs("maxEnergy");
        agent.addBelief(new LogicBelief("maxEnergy", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("role")) {
        agent.addBelief(new LogicBelief("role", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("visRange")) {
        agent.removeBeliefs("visRange");
        agent.addBelief(new LogicBelief("visRange", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("step")) {
        agent.removeBeliefs("step");
        agent.addBelief(new LogicBelief("step", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("score")) {
        agent.removeBeliefs("score");
        agent.addBelief(new LogicBelief("score", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("zoneScore")) {
        agent.removeBeliefs("zoneScore");
        agent.addBelief(new LogicBelief("zoneScore", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("zonesScore")) {
        agent.removeBeliefs("zonesScore");
        agent.addBelief(new LogicBelief("zonesScore", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("lastStepScore")) {
        agent.removeBeliefs("lastStepScore");
        agent.addBelief(new LogicBelief("lastStepScore", p.getParameters().get(0).toString()));
      } else if (p.getName().equals("probedVertex")) {
        if (!agent.getAllBeliefs("vertex", p.getParameters().get(0).toString()).isEmpty()) {
          agent.updateBelief(
              agent.getAllBeliefs("vertex", p.getParameters().get(0).toString()).getFirst(),
              new LogicBelief(
                  "vertex",
                  p.getParameters().get(0).toString(),
                  p.getParameters().get(1).toString()));
        }
      } else if (p.getName().equals("visibleEntity")) {
        if (agent.getAllBeliefs("enemyTeam").isEmpty()
            && !p.getParameters().get(3).equals(agent.getTeam())) {
          LogicBelief belief = new LogicBelief("enemyTeam", p.getParameters().get(3).toString());
          agent.addBelief(belief);
          agent.broadcastBelief(belief);
        }
        agent.addBelief(
            new LogicBelief(
                "visibleEntity",
                agent.getName(),
                p.getParameters().get(0).toString(),
                p.getParameters().get(1).toString(),
                p.getParameters().get(2).toString(),
                p.getParameters().get(3).toString()));
      } else if (p.getName().equals("surveyedEdge")) {
        if (!agent
            .getAllBeliefs(
                "edge", p.getParameters().get(0).toString(), p.getParameters().get(1).toString())
            .isEmpty()) {
          agent.updateBelief(
              agent
                  .getAllBeliefs(
                      "edge",
                      p.getParameters().get(0).toString(),
                      p.getParameters().get(1).toString())
                  .getFirst(),
              new LogicBelief(
                  "edge",
                  p.getParameters().get(0).toString(),
                  p.getParameters().get(1).toString(),
                  p.getParameters().get(2).toString()));
        } else {
          agent.addBelief(
              new LogicBelief(
                  "edge",
                  p.getParameters().get(0).toString(),
                  p.getParameters().get(1).toString(),
                  p.getParameters().get(2).toString()));
        }
      } else if (p.getName().equals("inspectedEntity")) {
        if (!p.getParameters().get(1).equals(agent.getTeam())) {
          LogicBelief newBelief =
              new LogicBelief(
                  "inspectedEntity",
                  p.getParameters().get(0).toString(),
                  p.getParameters().get(1).toString(),
                  p.getParameters().get(2).toString(),
                  p.getParameters().get(3).toString(),
                  p.getParameters().get(4).toString(),
                  p.getParameters().get(5).toString(),
                  p.getParameters().get(6).toString(),
                  p.getParameters().get(7).toString(),
                  p.getParameters().get(8).toString(),
                  p.getParameters().get(9).toString());
          agent.addBelief(newBelief);
          agent.broadcastBelief(newBelief);
        }
      }
    }
    for (LogicBelief b : agent.getAllBeliefs("edge")) {
      if (agent.getAllBeliefs("vertex", b.getParameters().get(0)).isEmpty()) {
        LogicBelief newBelief =
            new LogicBelief("vertex", b.getParameters().get(0).toString(), "-1");
        agent.addBelief(newBelief);
        // broadcastBelief(newBelief);
      }
      if (agent.getAllBeliefs("vertex", b.getParameters().get(1)).isEmpty()) {
        LogicBelief newBelief =
            new LogicBelief("vertex", b.getParameters().get(1).toString(), "-1");
        agent.addBelief(newBelief);
        // broadcastBelief(newBelief);
      }
    }
    return null;
  }