Ejemplo n.º 1
0
  public void draw() {
    background(
        theme.getColor(Types.BACKGROUND)); // Draws background, basically refreshes the screen
    win.setBackground(theme.getColor(Types.BACKGROUND));
    sidePanel.setBackground(theme.getColor(Types.SIDEPANEL1));

    for (int i = 0; i < SIM_TICKS; i++) {
      env.updateAllAgents(); // 'Ticks' for the new frame, sensors sense, networks network and
      // collisions are checked.
      env.updateCollisions(); // update the environment with the new collisions
      env.updateAgentsSight(); // update all the agents to everything they can see in their field
      // of view
      handleCollisions();
      if (!env.fitnessOnly) {
        checkDeaths();
      }
      updateUI();

      autoSnapshot();
    }

    // move drawn region
    if (arrowsPressed[0] && !arrowsPressed[1]) offsetY -= moveSpeed * zoomLevel; // UP
    if (arrowsPressed[1] && !arrowsPressed[0]) offsetY += moveSpeed * zoomLevel; // DOWN
    if (arrowsPressed[2] && !arrowsPressed[3]) offsetX -= moveSpeed * zoomLevel; // LEFT
    if (arrowsPressed[3] && !arrowsPressed[2]) offsetX += moveSpeed * zoomLevel; // RIGHT

    win.draw();

    fill(255);
    text("FrameRate: " + frameRate, 10, 10); // Displays framerate in the top left hand corner
    text("Mouse X: " + mouseX + "Mouse Y: " + mouseY, 10, 30);
    text("Fish Generation: " + env.getFishGeneration(), 10, 50);
    text("Ticks to next fish generation: " + (1000 - (env.getTick() % 1000)), 10, 70);
  }
Ejemplo n.º 2
0
  private void autoSnapshot() {
    int generation = env.getFishGeneration();

    if (AUTO_SNAPSHOT == -1
        || generation == 0
        || generation % AUTO_SNAPSHOT != 0
        || (1000 - (env.getTick() % 1000)) != 1000) return;

    new File(System.getProperty("user.home") + "/anemone/auto_snapshot/").mkdirs();
    String filename =
        System.getProperty("user.home")
            + "/anemone/auto_snapshot/"
            + AUTO_SNAPSHOT_NAME
            + "_"
            + generation
            + ".env";
    saveSnapshot(filename);
  }