Ejemplo n.º 1
0
  /**
   * Get reference to Entity at position p
   *
   * @param p Position to look
   * @return Entity at position p
   */
  public Entity get(AbsPos p) {
    if (!grid.isInBounds(p)) {
      return TO_APPEAR_OUTSIDE_GRID;
    }

    Entity found = grid.get(p);
    return found;
  }
Ejemplo n.º 2
0
  /*TODO should only happen in tick phase...
   * Otherwise two bots could validly reproduce into same cell...
   * one would succeed and the other would not.
   * Or would kill the newborn or something.  Bad.
   */
  public void addNewEntity(AbsPos target, Entity toAdd) {
    // target position for new entity should be empty
    checkNotNull(toAdd);
    assert (grid.get(target) != DEBUG_PENDING_CHANGE_PLACEHOLDER);
    assert (grid.get(target) == null);
    assert (!addBuffer.contains(toAdd));

    grid.set(
        target,
        DEBUG_PENDING_CHANGE_PLACEHOLDER); // TODO removeme; pending new ent; don't want anything
                                           // else to happen here
    addBuffer.add(new Entry<Entity>(target, toAdd));
  }
Ejemplo n.º 3
0
  /**
   * Gets reference to a bot
   *
   * @param botID
   * @return Reference to bot with given ID
   */
  public BotEntity get(int botID) {
    // should never try to get a bot and find it's not there
    assert (botIndex.containsKey(botID));

    AbsPos pos = botIndex.get(botID);

    BotEntity found = (BotEntity) grid.get(pos);
    return found;
  }
Ejemplo n.º 4
0
  private void flushRemoveBuffer() {
    while (!removeBuffer.isEmpty()) {
      Entity fakeEntToDie = removeBuffer.remove();

      Entry<Entity> entry = grid.get(fakeEntToDie);
      AbsPos pos = entry.getPosition();
      Entity entToDie = entry.getContents();

      if (entToDie instanceof BotEntity) {
        BotEntity botToDie = ((BotEntity) entToDie);
        botIndex.remove(botToDie.getID());
      }

      grid.set(pos, null);

      MatchLog.removeEntity(entToDie);
    }
  }
Ejemplo n.º 5
0
  private void flushAddBuffer() {
    while (!addBuffer.isEmpty()) {
      Entry<Entity> entry = addBuffer.remove();
      Entity toAdd = entry.getContents();
      AbsPos addPos = entry.getPosition();

      assert (!grid.contains(toAdd));
      assert (grid.get(addPos) == DEBUG_PENDING_CHANGE_PLACEHOLDER);

      if (toAdd instanceof BotEntity) {
        BotEntity newBot = (BotEntity) toAdd;
        botIndex.put(newBot.getID(), addPos);
      }

      grid.set(addPos, toAdd);

      MatchLog.addEntity(toAdd, addPos);
    }
  }
Ejemplo n.º 6
0
 /** Skips nulls */
 public Iterable<Entry<Entity>> getEntries() {
   return Iterables.filter(
       grid.getEntries(),
       new Predicate<Entry<Entity>>() {
         @Override
         public boolean apply(Entry<Entity> input) {
           return input.getContents() != null;
         };
       });
 }
Ejemplo n.º 7
0
  /** Get list of all bots on map in a certain team */
  public Iterable<BotEntity> getTeamBots(final Team team) {
    List<BotEntity> ret = new ArrayList<>();

    for (AbsPos botPos : botIndex.values()) {
      BotEntity bot = (BotEntity) grid.get(botPos);
      if (bot.getTeam().equals(team)) {
        ret.add(bot);
      }
    }

    return ret;
  }
Ejemplo n.º 8
0
  public void swap(AbsPos a, AbsPos b) {
    Entity aEnt = get(a);
    if (aEnt instanceof BotEntity) {
      botIndex.put(((BotEntity) aEnt).getID(), b);
    }

    Entity bEnt = get(b);
    if (bEnt instanceof BotEntity) {
      botIndex.put(((BotEntity) bEnt).getID(), a);
    }

    grid.set(a, bEnt);
    grid.set(b, aEnt);
  }
Ejemplo n.º 9
0
 @Override
 public String toString() {
   return grid.toString();
 }
Ejemplo n.º 10
0
 public Dimension getSize() {
   return grid.getSize();
 }
Ejemplo n.º 11
0
 public boolean isInBounds(AbsPos pos) {
   return grid.isInBounds(pos);
 }