From c88a8700b7683e67776c4d3b0a58087575cb8a26 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Wed, 8 Jul 2015 19:15:24 +0200 Subject: [PATCH] Fix a small bug --- core/src/logic/World.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/logic/World.java b/core/src/logic/World.java index c91e070..6e7aceb 100644 --- a/core/src/logic/World.java +++ b/core/src/logic/World.java @@ -30,6 +30,7 @@ public class World implements Runnable { private Map options; private long ticksSinceGenStart = 0, maximumTicksPerGen = 0; private Creature selected; + private Comparator creatureComp; private final ArrayList elements; private final ArrayList toAdd; private final ArrayList creatures; @@ -53,6 +54,14 @@ public class World implements Runnable { graveyard = new ArrayList(); listeners = new ArrayList(); selected = null; + creatureComp = new Comparator() { + + @Override + public int compare(Creature t, Creature t1) { + // put the highest fitness first (sort in reverse) + return (int) (t1.getFitness() - t.getFitness()); + } + }; newGen(true); } @@ -108,7 +117,7 @@ public class World implements Runnable { ticksSinceGenStart++; if (maximumTicksPerGen > 0 && ticksSinceGenStart >= maximumTicksPerGen) { // Force new gen - Log.log(Log.INFO, "Reached maximum generation time ("+maximumTicksPerGen+")"); + Log.log(Log.INFO, "Reached maximum generation time (" + maximumTicksPerGen + ")"); newGen(false); } for (Element e : toAdd) { @@ -174,14 +183,6 @@ public class World implements Runnable { selected = null; Log.log(Log.INFO, "Cleared selection"); } - Comparator creatureComp = new Comparator() { - - @Override - public int compare(Creature t, Creature t1) { - // put the highest fitness first (sort in reverse) - return (int) (t1.getFitness() - t.getFitness()); - } - }; if (graveyard.isEmpty() || restart) { // First gen generation = 1; Log.log(Log.INFO, "Starting from generation 1: spawning " + creatPerGen + " creatures."); @@ -211,7 +212,7 @@ public class World implements Runnable { avgFitness += c.getFitness(); } avgFitness = avgFitness / graveyard.size(); - Log.log(Log.INFO, "Gen " + generation + " done. Ticks: "+ticksSinceGenStart+". Avg fitness: " + avgFitness); + Log.log(Log.INFO, "Gen " + generation + " done. Ticks: " + ticksSinceGenStart + ". Avg fitness: " + avgFitness); ticksSinceGenStart = 0; // Generate children for (Creature c : graveyard) {