/**
   * Sets the face and passable value of the tile at the specified (x, y) location.
   *
   * @param face the new face of the tile
   * @param passable the new passable value of the tile
   * @param x the x value of the position being updated
   * @param y the y value of the position being updated
   */
  public void setTile(ColoredChar face, boolean passable, int x, int y) {
    Guard.argumentIsNotNull(face);
    Guard.argumentsInsideBounds(x, y, width, height);

    grid[x][y].face = face;
    grid[x][y].passable = passable;
  }
  /**
   * Removes an {@code Actor} from the {@code World}. The {@code Actor} must be both bound to this
   * {@code World} and not held by another {@code Actor}. However, if the {@code Actor} is expired,
   * it may always be removed.
   *
   * @param actor the {@code Actor} to be removed
   */
  public void removeActor(Actor actor) {
    Guard.argumentIsNotNull(actor);
    Guard.verifyState(actor.bound(this));
    Guard.verifyState(!actor.held() || actor.expired());

    unregisterActor(actor);
    removeFromGrid(actor);
    actor.setWorld(null);
  }
  /**
   * Adds an {@code Actor} to the {@code World} at the specified location.
   *
   * @param actor the {@code World} being added
   * @param x the x location of the {@code Actor}
   * @param y the y location of the {@code Actor}
   */
  public void addActor(Actor actor, int x, int y) {
    Guard.argumentIsNotNull(actor);
    Guard.argumentsInsideBounds(x, y, width, height);
    Guard.verifyState(!actor.bound());
    Guard.verifyState(!actor.held());

    actor.setWorld(this);
    actor.setXY(x, y);
    addToGrid(actor);
    registerActor(actor);
  }
  /**
   * Gets a randomly chosen open tile on the {@code World} within the given bounds. If after 100
   * randomly selected tiles are closed, then each tile will be checked and the first open tile
   * found is returned. If the entire {@code World} is closed, null is returned.
   *
   * @param dice the random number generator used to randomly select tiles
   * @param x1 the bounds left most value
   * @param y1 the bounds upper most value
   * @param x2 the bounds right most value
   * @param y2 the bounds bottom most value
   * @return a randomly chosen open tile
   */
  public Coordinate getOpenTile(Dice dice, int x1, int y1, int x2, int y2) {
    Guard.argumentIsNotNull(dice);
    Guard.argumentsInsideBounds(x1, y1, width, height);
    Guard.argumentsInsideBounds(x2, y2, width, height);

    for (int i = 0; i < 100; i++) {
      int x = dice.nextInt(x1, x2);
      int y = dice.nextInt(y1, y2);
      if (passableAt(x, y)) return new Coordinate(x, y);
    }

    for (int x = x1; x <= x2; x++)
      for (int y = y1; y <= y2; y++) if (passableAt(x, y)) return new Coordinate(x, y);

    return null;
  }
  /**
   * Sets the face and passable value of the tile at the specified {@code Coordinate}.
   *
   * @param face the new face of the tile
   * @param passable the new passable value of the tile
   * @param coord the value of the position being updated
   */
  public final void setTile(ColoredChar face, boolean passable, Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    setTile(face, passable, coord.x(), coord.y());
  }
  /**
   * Returns true if the tile at the provided {@code Coordinate} is passable.
   *
   * @param coord the value of the position being queried
   * @return true if the tile at the given {@code Coordinate}
   */
  public final boolean passableAt(Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    return passableAt(coord.x(), coord.y());
  }
  /**
   * Returns the face of the tile at the provided coordinates.
   *
   * @param coord the value of the position being queried
   * @return the face of the tile at then given {@code Coordinate}
   */
  public final ColoredChar tileAt(Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    return tileAt(coord.x(), coord.y());
  }
  /**
   * Returns the face that should be drawn for the given location.
   *
   * @param pos the location being queried
   * @return the face that should be drawn for the given location.
   */
  public final ColoredChar look(Coordinate pos) {
    Guard.argumentIsNotNull(pos);

    return look(pos.x(), pos.y());
  }
  /**
   * Returns every tile that is visible at a given location, ordered such that the tile with highest
   * priority (the tile returned by look) is first, and the lowest priority is last. This last tile
   * will be the face of the actual tile itself. Note that any actor which has a null face will not
   * be included.
   *
   * @param pos the location being queried
   * @return every tile that is visible at a given location
   */
  public final List<ColoredChar> lookAll(Coordinate pos) {
    Guard.argumentIsNotNull(pos);

    return lookAll(pos.x(), pos.y());
  }
  /**
   * Returns a {@code Collection<T extends Actor>} of all {@code Actor} of the given class at the
   * given location.
   *
   * @param <T> the generic type of the class type to be returned
   * @param cls the {@code Class<T extends Actor>} of the {@code Actor} to be returned
   * @param pos the location being queried
   * @return a {@code Collection<T extends Actor>} of all {@code Actor} of the given class located
   *     at (x, y)
   */
  public final <T extends Actor> Collection<T> getActorsAt(Class<T> cls, Coordinate pos) {
    Guard.argumentIsNotNull(pos);

    return getActorsAt(cls, pos.x(), pos.y());
  }
  /**
   * Adds an {@code Actor} to the {@code World} at the specified location.
   *
   * @param actor the {@code World} being added
   * @param coord the location of the {@code Actor}
   */
  public final void addActor(Actor actor, Coordinate coord) {
    Guard.argumentIsNotNull(coord);

    addActor(actor, coord.x(), coord.y());
  }
  /**
   * Returns the sum of all values across a particular {@code Categorical}.
   *
   * @param key the key of the {@code Categorical} being queried
   * @return the sum of all values in the specified {@code Categorical}
   */
  public int sumCountGiven(K key) {
    Guard.argumentIsNotNull(key);

    return getCategorical(key).sumCounts();
  }