Examples of WarbotMessage


Examples of warbot.kernel.WarbotMessage

  }

  @Override
  protected void CheckMessages() {
    WarbotMessage msg = null;
    ArrayList<KnightCandidate> candidates = new ArrayList<KnightCandidate>();

    while (!isMessageBoxEmpty()) {
      msg = readMessage();
      if (msg.getSender() == msg.getReceiver())
        continue;

      if (msg.getAct().equals(Cst.Msg.helpRT)) {
        AgentAddress k_aa = msg.getSender();
        double k_x = msg.getFromX();
        double k_y = msg.getFromY();
        int k_hp = Integer.parseInt(msg.getArg1());
        double k_score = DefinePriority(k_x, k_y, k_hp);
        KnightCandidate k = new KnightCandidate(k_aa, k_score);
        candidates.add(k);
      } else if (msg.getAct().equals(Cst.Msg.Goal.help))
        missions.add(new Mission(msg.getArg1(), msg.getSender(),
            Cst.Msg.Goal.help, new WBPoint(msg.getFromX(), msg.getFromY())));
      else if (msg.getAct().equals(Cst.Msg.dead)) {
        missions.remove(msg.getSender());
        affect.remove(msg.getSender());
      } else if (msg.getAct().equals(Cst.Msg.cancel))
        missions.remove(msg.getSender(), msg.getArg1());
      else if (msg.getAct().equals(Cst.Msg.goalReq))
        AffectWB(msg.getSender(), msg.getArg1());
      else if (msg.getAct().equals(Cst.Msg.ko)) {
        if (msg.getArg1().equals(Cst.Msg.goalRep))
          affect.remove(msg.getSender());
      } else if (msg.getAct().equals(Cst.Msg.masterRep))
        bases.put(msg.getSender().getLocalID(), new AAetWB(msg.getSender(),
            -msg.getFromX(), -msg.getFromY()));
      else if (msg.getAct().equals(Cst.Msg.masterReq))
        send(msg.getSender(), Cst.Msg.masterRep);
      else if (msg.getAct().equals(Cst.Msg.posReq) && posToRef != null) {
        Say("Answer pos Req");
        send(msg.getSender(), Cst.Msg.posRep, posToRef.toStrings());
      } else if (msg.getAct().equals(Cst.Msg.ping))
        send(msg.getSender(), Cst.Msg.pong, "Base");
      else if (msg.getAct().equals(Cst.Msg.refreshMission)) {
        int nbDefend = affect.size(MissionType.HELP);
        int nbAttack = affect.size(MissionType.ATTACK);

        if (msg.getArg1().equals(Cst.Msg.Goal.help))
          if (nbAttack <= ratioDefAtta * (nbDefend - 1)) {
            send(msg.getSender(), Cst.Msg.cancel, Cst.Msg.Goal.help);
            affect.remove(msg.getSender());
          }
      }
    }
    Collections.sort(candidates);
    int i = 0;
View Full Code Here

Examples of warbot.kernel.WarbotMessage

    return false;
  }

  @Override
  protected void CheckMessages() {
    WarbotMessage msg = null;

    TreeMap<KnightCandidate, Mission> boss = new TreeMap<KnightCandidate, Mission>();
    ArrayList<KnightCandidate> candidatesAttack = new ArrayList<KnightCandidate>();
    ArrayList<KnightCandidate> candidatesHelp = new ArrayList<KnightCandidate>();
    ArrayList<KnightCandidate> candidatesFood = new ArrayList<KnightCandidate>();

    // TODO: Check Message
    while (!isMessageBoxEmpty()) {
      msg = readMessage();
      if (msg.getSender() == msg.getReceiver())
        continue;
      if (!MessageRefPos(msg) && !CommonMessages(msg))
        if (msg.getAct().equals(Cst.Msg.goalRep)) {
          AgentAddress k_aa = msg.getSender();
          double k_x = msg.getFromX();
          double k_y = msg.getFromY();
          double k_score = DefinePriority(k_x, k_y, 1);
          KnightCandidate k = new KnightCandidate(k_aa, k_score + 100
              * Double.parseDouble(msg.getArg1()));
          boss.put(k, new Mission(msg.getArg1(), msg.getSender(),
              msg.getArg2(), toWBPoint(msg)));
          Say("RLauncher receive goal response");
        } else if (msg.getAct().equals(Cst.Msg.Goal.help)) {
          if (missions.isEmpty()
              || Cst.Priority.compareTo(missions.first().getPriority(),
                  msg.getArg1()) > 0) {
            WBPoint pos = msg.getLength() > 1 ? new WBPoint(
                Double.parseDouble(msg.getArgN(2)), Double.parseDouble(msg
                    .getArgN(3))) : toWBPoint(msg);
            Mission mission = new Mission(msg.getArg1(), msg.getSender(),
                Cst.Msg.Goal.help, pos);
            if (!missions.add(mission))
              Say("Didn't add mission.");
            else
              send(msg.getSender(), Cst.Msg.helpRT,
                  new String[] { Integer.toString(getEnergyLevel()) });
          } else if (msg.getSender() == missions.first().getNakamaAddress())
            send(msg.getSender(), Cst.Msg.helpRT,
                new String[] { Integer.toString(getEnergyLevel()) });
        } else if (msg.getAct().equals(Cst.Msg.pong)) {
          double radius = msg.getArg1().equals("Mobile") ? 22 : 32;
          allies.put(msg.getSender(), new Ally(toWBPoint(msg), radius));
        } else if (msg.getAct().equals(Cst.Msg.refreshMission)) {
          if (msg.getArg1().equals(Cst.Msg.Goal.attack)
              && !missions.first().getMissionType()
                  .equals(Mission.MissionType.ATTACK))
            send(msg.getSender(), Cst.Msg.cancel, Cst.Msg.Goal.attack);

        } else if (msg.getAct().equals(Cst.Msg.attackRT)) {
          double k_score = DefinePriority(msg.getFromX(), msg.getFromY(), 1);
          KnightCandidate k = new KnightCandidate(msg.getSender(), k_score);
          candidatesAttack.add(k);
        } else if (msg.getAct().equals(Cst.Msg.helpRT)) {
          int k_hp = Integer.parseInt(msg.getArg1());
          double k_score = DefinePriority(msg.getFromX(), msg.getFromY(), k_hp);
          KnightCandidate k = new KnightCandidate(msg.getSender(), k_score);
          candidatesHelp.add(k);
        } else if (msg.getAct().equals(Cst.Msg.helpRT)) {
          double k_score = Integer.parseInt(msg.getArg1());
          KnightCandidate k = new KnightCandidate(msg.getSender(), k_score);
          candidatesFood.add(k);
        } else if (msg.getAct().equals(Cst.Msg.Goal.explore))
          explore = true;
    }
    if (candidatesAttack.size() > 0) {
      Collections.sort(candidatesAttack);

View Full Code Here

Examples of warbot.kernel.WarbotMessage

      target = toWBPoint(p);
  }

  @Override
  protected void CheckMessages() {
    WarbotMessage msg = null;
    TreeMap<KnightCandidate, Mission> boss = new TreeMap<KnightCandidate, Mission>();

    // TODO: Check Message
    while (!isMessageBoxEmpty()) {
      msg = readMessage();
      if (msg.getSender() == msg.getReceiver())
        continue;

      if (!MessageRefPos(msg) && !CommonMessages(msg) && posToRef != null)
        if (msg.getAct().equals(Cst.Msg.goalRep)) {
          if (msg.getLength() <= 1)
            continue;
          AgentAddress k_aa = msg.getSender();
          double k_x = msg.getFromX();
          double k_y = msg.getFromY();
          double k_score = DefinePriority(k_x, k_y, 1);
          KnightCandidate k = new KnightCandidate(k_aa, k_score + 100
              * Double.parseDouble(msg.getArg1()));
          boss.put(k, new Mission(msg.getArg1(), msg.getSender(),
              msg.getArg2(), toWBPoint(msg)));
          Say("Explorer receive goal response");

        } else if (msg.getAct().equals(Cst.Msg.Goal.attack)) {
          if (msg.getLength() < 1)
            continue;
          Say("Receive Mission : attack");
          if (missions.isEmpty()
              || Cst.Priority.compareTo(missions.first().getPriority(),
                  msg.getArg1()) > 0) {

            WBPoint pos;
            if (msg.getLength() > 2)
              pos = new WBPoint(Double.parseDouble(msg.getArgN(2)),
                  Double.parseDouble(msg.getArgN(3)));
            else
              pos = toWBPoint(msg);
            Mission mission = new Mission(msg.getArg1(), msg.getSender(),
                Cst.Msg.Goal.help, pos);
            if (!missions.add(mission))
              Say("Didn't add mission.");
            else
              send(msg.getSender(), Cst.Msg.attackRT);
          } else if (!missions.isEmpty()
              && msg.getSender() == missions.first().getNakamaAddress())
            send(msg.getSender(), Cst.Msg.attackRT);
        } else if (msg.getAct().equals(Cst.Msg.Goal.help)) {
          Mission mission = new Mission("1", msg.getSender(),
              Cst.Msg.Goal.help, toWBPoint(msg));

          if (!missions.add(mission))
            Say("Didn't add mission.");
          else if (mission != null) {
            double score = posToRef.distance(mission.getLocation());;
            InterestPoint pantry = points.getNearest(InterestPoint.Type.Pantry,
                posToRef);
            if (bagSize() == 0 && pantry != null)
              score = score * 2 + pantry.distance(posToRef);
            send(msg.getSender(), Cst.Msg.foodRT, Double.toString(score));
          }
        }
    }

    if (boss.size() > 0) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.