mirror of
https://github.com/fazo96/AIrium.git
synced 2025-01-24 11:44:21 +01:00
Fix a small bug
This commit is contained in:
parent
c7add97a1e
commit
c88a8700b7
@ -30,6 +30,7 @@ public class World implements Runnable {
|
|||||||
private Map<String, Float> options;
|
private Map<String, Float> options;
|
||||||
private long ticksSinceGenStart = 0, maximumTicksPerGen = 0;
|
private long ticksSinceGenStart = 0, maximumTicksPerGen = 0;
|
||||||
private Creature selected;
|
private Creature selected;
|
||||||
|
private Comparator creatureComp;
|
||||||
private final ArrayList<Element> elements;
|
private final ArrayList<Element> elements;
|
||||||
private final ArrayList<Element> toAdd;
|
private final ArrayList<Element> toAdd;
|
||||||
private final ArrayList<Creature> creatures;
|
private final ArrayList<Creature> creatures;
|
||||||
@ -53,6 +54,14 @@ public class World implements Runnable {
|
|||||||
graveyard = new ArrayList();
|
graveyard = new ArrayList();
|
||||||
listeners = new ArrayList();
|
listeners = new ArrayList();
|
||||||
selected = null;
|
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);
|
newGen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +117,7 @@ public class World implements Runnable {
|
|||||||
ticksSinceGenStart++;
|
ticksSinceGenStart++;
|
||||||
if (maximumTicksPerGen > 0 && ticksSinceGenStart >= maximumTicksPerGen) {
|
if (maximumTicksPerGen > 0 && ticksSinceGenStart >= maximumTicksPerGen) {
|
||||||
// Force new gen
|
// Force new gen
|
||||||
Log.log(Log.INFO, "Reached maximum generation time ("+maximumTicksPerGen+")");
|
Log.log(Log.INFO, "Reached maximum generation time (" + maximumTicksPerGen + ")");
|
||||||
newGen(false);
|
newGen(false);
|
||||||
}
|
}
|
||||||
for (Element e : toAdd) {
|
for (Element e : toAdd) {
|
||||||
@ -174,14 +183,6 @@ public class World implements Runnable {
|
|||||||
selected = null;
|
selected = null;
|
||||||
Log.log(Log.INFO, "Cleared selection");
|
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
|
if (graveyard.isEmpty() || restart) { // First gen
|
||||||
generation = 1;
|
generation = 1;
|
||||||
Log.log(Log.INFO, "Starting from generation 1: spawning " + creatPerGen + " creatures.");
|
Log.log(Log.INFO, "Starting from generation 1: spawning " + creatPerGen + " creatures.");
|
||||||
@ -211,7 +212,7 @@ public class World implements Runnable {
|
|||||||
avgFitness += c.getFitness();
|
avgFitness += c.getFitness();
|
||||||
}
|
}
|
||||||
avgFitness = avgFitness / graveyard.size();
|
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;
|
ticksSinceGenStart = 0;
|
||||||
// Generate children
|
// Generate children
|
||||||
for (Creature c : graveyard) {
|
for (Creature c : graveyard) {
|
||||||
|
Loading…
Reference in New Issue
Block a user