Ejemplo n.º 1
0
  /**
   * Show the current status of the field.
   *
   * @param step Which iteration step it is.
   * @param field Which field to display
   */
  public void showStatus(int step, Field field) {
    if (!isVisible()) setVisible(true);

    stepLabel.setText(STEP_PREFIX + step);

    stats.reset();
    fieldView.preparePaint();

    for (int row = 0; row < field.getDepth(); row++) {
      for (int col = 0; col < field.getWidth(); col++) {
        Object creature;
        creature = field.getObjectAt(row, col);
        if (creature != null) {
          stats.incrementCount(creature.getClass());
          fieldView.drawMark(col, row, getColor(creature.getClass()));
        } else {
          fieldView.drawMark(col, row, EMPTY_COLOR);
        }
      }
    }
    stats.countFinished();

    population.setText(POPULATION_PREFIX + stats.getPopulationDetails(field));
    fieldView.repaint();
  }
Ejemplo n.º 2
0
 /**
  * Determine whether the simulation should continue to run.
  *
  * @return true If there is more than one species alive.
  */
 public boolean isViable(Field field) {
   return stats.isViable(field);
 }