Skip to content

Commit

Permalink
Fix a small bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fazo96 committed Jul 8, 2015
1 parent c7add97 commit c88a870
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions core/src/logic/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class World implements Runnable {
private Map<String, Float> options;
private long ticksSinceGenStart = 0, maximumTicksPerGen = 0;
private Creature selected;
private Comparator creatureComp;
private final ArrayList<Element> elements;
private final ArrayList<Element> toAdd;
private final ArrayList<Creature> creatures;
Expand All @@ -53,6 +54,14 @@ public World(Map<String, Float> options) {
graveyard = new ArrayList();
listeners = new ArrayList();
selected = null;
creatureComp = new Comparator<Creature>() {

@Override
public int compare(Creature t, Creature t1) {
// put the highest fitness first (sort in reverse)
return (int) (t1.getFitness() - t.getFitness());
}
};
newGen(true);
}

Expand Down Expand Up @@ -108,7 +117,7 @@ public void update() {
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) {
Expand Down Expand Up @@ -174,14 +183,6 @@ private void newGen(boolean restart) {
selected = null;
Log.log(Log.INFO, "Cleared selection");
}
Comparator creatureComp = new Comparator<Creature>() {

@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.");
Expand Down Expand Up @@ -211,7 +212,7 @@ public int compare(Creature t, Creature t1) {
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) {
Expand Down

0 comments on commit c88a870

Please sign in to comment.