1
0
mirror of https://github.com/fazo96/AIrium.git synced 2025-01-10 09:34:20 +01:00

Optimization and bug fixing

This commit is contained in:
Enrico Fasoli 2015-08-10 15:59:47 +02:00
parent 5c44b30cc6
commit b0251e1626
5 changed files with 365 additions and 353 deletions

View File

@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Map;
import logic.creatures.Creature; import logic.creatures.Creature;
import logic.Element; import logic.Element;
import logic.World; import logic.World;

View File

@ -1,204 +1,204 @@
package com.mygdx.game; package com.mygdx.game;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
/** /**
* Hangles File I/O for AIrium components. * Hangles File I/O for AIrium components.
* *
* @author fazo * @author fazo
*/ */
public class Serializer { public class Serializer {
private static final String[] sillabe = {"ba", "de", "ka", "mo", "shi", "du", "ro", "te", "mi", "lo", "pa"}; private static final String[] sillabe = {"ba", "de", "ka", "mo", "shi", "du", "ro", "te", "mi", "lo", "pa"};
private static Map<String, Float> defaults; private static Map<String, Float> defaults;
public static String nameBrain(float[][][] brainMap) { public static String nameBrain(float[][][] brainMap) {
// Compute a unique representation of the brainmap // Compute a unique representation of the brainmap
long a = 0; long a = 0;
for (int i = 0; i < brainMap.length; i++) { for (int i = 0; i < brainMap.length; i++) {
for (int j = 0; j < brainMap[i].length; j++) { for (int j = 0; j < brainMap[i].length; j++) {
for (int z = 0; z < brainMap[i][j].length; z++) { for (int z = 0; z < brainMap[i][j].length; z++) {
a += brainMap[i][j][z] * i * j * z; a += brainMap[i][j][z] * i * j * z;
} }
} }
} }
Random gen = new Random(a); Random gen = new Random(a);
String name = ""; String name = "";
int length = Math.abs(gen.nextInt()) % 5 + 2; int length = Math.abs(gen.nextInt()) % 5 + 2;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
name += sillabe[Math.abs(gen.nextInt()) % sillabe.length]; name += sillabe[Math.abs(gen.nextInt()) % sillabe.length];
} }
return name; return name;
} }
public static void saveToFile(File f, String content) { public static void saveToFile(File f, String content) {
PrintWriter fw = null; PrintWriter fw = null;
try { try {
fw = new PrintWriter(f); fw = new PrintWriter(f);
} catch (IOException ex) { } catch (IOException ex) {
Log.log(Log.ERROR, ex.getMessage()); Log.log(Log.ERROR, ex.getMessage());
} }
fw.print(content); fw.print(content);
fw.flush(); fw.flush();
fw.close(); fw.close();
} }
public static String loadFromFile(File f) { public static String loadFromFile(File f) {
String s, a = ""; String s, a = "";
try { try {
BufferedReader bf = new BufferedReader(new FileReader(f)); BufferedReader bf = new BufferedReader(new FileReader(f));
while ((s = bf.readLine()) != null) { while ((s = bf.readLine()) != null) {
a += s + "\n"; a += s + "\n";
} }
} catch (Exception e) { } catch (Exception e) {
Log.log(Log.ERROR, e.getMessage()); Log.log(Log.ERROR, e.getMessage());
System.out.println(e + ""); System.out.println(e + "");
} }
return a; return a;
} }
public static String serializeSettings(Map<String, Float> options) { public static String serializeSettings(Map<String, Float> options) {
String a = "# Settings file for use with AIrium.\n" String a = "# Settings file for use with AIrium.\n"
+ "# More information at http://github.com/fazo96/AIrium\n"; + "# More information at http://github.com/fazo96/AIrium\n";
for (Object o : options.entrySet().toArray()) { for (Object o : options.entrySet().toArray()) {
Map.Entry<String, Float> e = (Map.Entry<String, Float>) o; Map.Entry<String, Float> e = (Map.Entry<String, Float>) o;
a += e.getKey() + " = " + e.getValue() + "\n"; a += e.getKey() + " = " + e.getValue() + "\n";
} }
return a; return a;
} }
public static Map<String, Float> readSettings(String fileContent) { public static Map<String, Float> readSettings(String fileContent) {
int line = 0; int line = 0;
Map<String, Float> m = new HashMap<String, Float>(); Map<String, Float> m = new HashMap<String, Float>();
for (String s : fileContent.split("\n")) { for (String s : fileContent.split("\n")) {
line++; line++;
if (s.startsWith("#")) { if (s.startsWith("#")) {
// Skip comment // Skip comment
continue; continue;
} }
String[] ss = s.trim().split(" = "); String[] ss = s.trim().split(" = ");
try { try {
if (ss.length != 2) { if (ss.length != 2) {
throw new Exception("Invalid string at line " + line); throw new Exception("Invalid string at line " + line);
} }
Log.log(Log.DEBUG, "Loading setting \"" + ss[0].trim() + "\" with value \"" + Float.parseFloat(ss[1].trim()) + "\""); Log.log(Log.DEBUG, "Loading setting \"" + ss[0].trim() + "\" with value \"" + Float.parseFloat(ss[1].trim()) + "\"");
m.put(ss[0].trim(), Float.parseFloat(ss[1].trim())); m.put(ss[0].trim(), Float.parseFloat(ss[1].trim()));
} catch (Exception e) { } catch (Exception e) {
Log.log(Log.ERROR, e.getMessage()); Log.log(Log.ERROR, e.getMessage());
} }
} }
return m; return m;
} }
public static String serializeBrain(float brainMap[][][]) { public static String serializeBrain(float brainMap[][][]) {
String s = "# Neural Map for use with AIrium.\n" String s = "# Neural Map for use with AIrium.\n"
+ "# More information at http://github.com/fazo96/AIrium\n" + "# More information at http://github.com/fazo96/AIrium\n"
+ "Layers: " + (brainMap.length + 1); + "Layers: " + (brainMap.length + 1);
s += "\nInput Neurons: " + brainMap[0][0].length; s += "\nInput Neurons: " + brainMap[0][0].length;
s += "\n# Layer 1 Skipped because it's the input layer."; s += "\n# Layer 1 Skipped because it's the input layer.";
// layers (input layer not included in brain map) // layers (input layer not included in brain map)
for (int i = 0; i < brainMap.length; i++) { for (int i = 0; i < brainMap.length; i++) {
s += "\nLayer " + (i + 2) + " has " + brainMap[i].length + " neurons"; s += "\nLayer " + (i + 2) + " has " + brainMap[i].length + " neurons";
for (int j = 0; j < brainMap[i].length; j++) { // neurons for (int j = 0; j < brainMap[i].length; j++) { // neurons
s += "\nWeights for Layer " + (i + 2) + " Neuron " + (j + 1) + " = "; s += "\nWeights for Layer " + (i + 2) + " Neuron " + (j + 1) + " = ";
for (int z = 0; z < brainMap[i][j].length; z++) { // connections for (int z = 0; z < brainMap[i][j].length; z++) { // connections
s += brainMap[i][j][z] + " "; s += brainMap[i][j][z] + " ";
} }
} }
} }
return s; return s;
} }
public static float[][][] loadBrain(String s) { public static float[][][] loadBrain(String s) {
float brainMap[][][] = null; float brainMap[][][] = null;
Log.log(Log.INFO, "Loading brain from String with " + s.split("\n").length + " lines"); Log.log(Log.INFO, "Loading brain from String with " + s.split("\n").length + " lines");
for (String l : s.split("\n")) { for (String l : s.split("\n")) {
l = l.trim(); l = l.trim();
if (l.isEmpty() || l.startsWith("#")) { if (l.isEmpty() || l.startsWith("#")) {
// Skip comment // Skip comment
} else if (l.startsWith("Layers: ")) { } else if (l.startsWith("Layers: ")) {
// Set Layer number // Set Layer number
int layers = Integer.parseInt(l.split(" ")[1]) - 1; int layers = Integer.parseInt(l.split(" ")[1]) - 1;
brainMap = new float[layers][][]; brainMap = new float[layers][][];
Log.log(Log.INFO, "Loaded NLayers: " + layers); Log.log(Log.INFO, "Loaded NLayers: " + layers);
} else if (l.startsWith("Input Neurons")) { } else if (l.startsWith("Input Neurons")) {
int in = Integer.parseInt(l.split(" ")[2]); int in = Integer.parseInt(l.split(" ")[2]);
brainMap[0] = new float[in][0]; brainMap[0] = new float[in][0];
Log.log(Log.INFO, "Loaded NInputNeurons: " + in); Log.log(Log.INFO, "Loaded NInputNeurons: " + in);
} else if (l.startsWith("Layer ")) { } else if (l.startsWith("Layer ")) {
// Set neuron number for given layer // Set neuron number for given layer
String ll[] = l.split(" "); String ll[] = l.split(" ");
int layer = Integer.parseInt(ll[1]) - 2; int layer = Integer.parseInt(ll[1]) - 2;
int n = Integer.parseInt(ll[3]); int n = Integer.parseInt(ll[3]);
brainMap[layer] = new float[n][];//[layer>0?brainMap[layer-1].length:0]; brainMap[layer] = new float[n][];//[layer>0?brainMap[layer-1].length:0];
} else if (l.startsWith("Weights ")) { } else if (l.startsWith("Weights ")) {
// Set weights // Set weights
String ll[] = l.split(" "); String ll[] = l.split(" ");
int layer = Integer.parseInt(ll[3]) - 2; int layer = Integer.parseInt(ll[3]) - 2;
int neuron = Integer.parseInt(ll[5]) - 1; int neuron = Integer.parseInt(ll[5]) - 1;
int nWeights = ll.length - 7; int nWeights = ll.length - 7;
brainMap[layer][neuron] = new float[nWeights]; brainMap[layer][neuron] = new float[nWeights];
if (layer == 0) { if (layer == 0) {
Log.log(Log.DEBUG, "This weightmap is for brains with " + (nWeights) + " input neurons."); Log.log(Log.DEBUG, "This weightmap is for brains with " + (nWeights) + " input neurons.");
} else if (nWeights != brainMap[layer - 1].length) { } else if (nWeights != brainMap[layer - 1].length) {
Log.log(Log.ERROR, "WRONG WEIGHT NUMBER: prev layer has " Log.log(Log.ERROR, "WRONG WEIGHT NUMBER: prev layer has "
+ brainMap[layer - 1].length + " neurons, but only " + brainMap[layer - 1].length + " neurons, but only "
+ (nWeights) + (nWeights)
+ " weights are supplied to this neuron"); + " weights are supplied to this neuron");
} }
for (int i = 7; i < ll.length; i++) { for (int i = 7; i < ll.length; i++) {
brainMap[layer][neuron][i - 7] = Float.parseFloat(ll[i]); brainMap[layer][neuron][i - 7] = Float.parseFloat(ll[i]);
Log.log(Log.DEBUG, "Loading L" + layer + "N" + neuron + "W" + (i - 7) + " = " + brainMap[layer][neuron][i - 7]); Log.log(Log.DEBUG, "Loading L" + layer + "N" + neuron + "W" + (i - 7) + " = " + brainMap[layer][neuron][i - 7]);
} }
Log.log(Log.DEBUG, "Loaded " + (nWeights) + " Weights for Layer " + layer + " Neuron " + neuron); Log.log(Log.DEBUG, "Loaded " + (nWeights) + " Weights for Layer " + layer + " Neuron " + neuron);
} }
} }
Log.log(Log.INFO, "Loading complete."); Log.log(Log.INFO, "Loading complete.");
return brainMap; return brainMap;
} }
public static Map<String, Float> getDefaultSettings() { public static Map<String, Float> getDefaultSettings() {
if (defaults == null) { if (defaults == null) {
String s = "corpse_decay_rate = 0.0\n" String s = "corpse_decay_rate = 0.0\n"
+ "mutationFactor = 1.0\n" + "mutationFactor = 1.0\n"
+ "fps_limit = 60.0\n" + "fps_limit = 60.0\n"
+ "creature_hp_decay = 0.5\n" + "creature_hp_decay = 0.5\n"
+ "enable_multithreading = 1.0\n" + "enable_multithreading = 1.0\n"
+ "max_ticks = 0.0\n" + "max_ticks = 0.0\n"
+ "parents_count = 0.0\n" + "parents_count = 0.0\n"
+ "draw_view_cones = 0.0\n" + "draw_view_cones = 0.0\n"
+ "world_width = 2000.0\n" + "world_width = 2000.0\n"
+ "world_height = 2000.0\n" + "world_height = 2000.0\n"
+ "number_of_plants = 700.0\n" + "number_of_plants = 200.0\n"
+ "nMutatedNeurons = 0.2\n" + "nMutatedNeurons = 0.2\n"
+ "enable_corpses = 0.0\n" + "enable_corpses = 0.0\n"
+ "nMutatedBrains = 0.5\n" + "nMutatedBrains = 0.5\n"
+ "nMutatedConnections = 0.5\n" + "nMutatedConnections = 0.5\n"
+ "number_of_creatures = 25.0\n" + "number_of_creatures = 15.0\n"
+ "draw_sight_lines = 0.0\n" + "draw_sight_lines = 0.0\n"
+ "vegetable_size = 5\n" + "vegetable_size = 20\n"
+ "creature_max_hp = 100\n" + "creature_max_hp = 100\n"
+ "creature_fov = 1.5\n" + "creature_fov = 1.5\n"
+ "creature_hp_decay = 0.5\n" + "creature_hp_decay = 0.5\n"
+ "creature_max_speed = 3.0\n" + "creature_max_speed = 3.0\n"
+ "creature_hp_for_attacking = 1.0\n" + "creature_hp_for_attacking = 1.0\n"
+ "creature_hp_for_eating_plants = 1.0\n" + "creature_hp_for_eating_plants = 1.0\n"
+ "creature_points_for_eating_plants = 1.0\n" + "creature_points_for_eating_plants = 1.0\n"
+ "creature_points_for_attacking = 2.0\n" + "creature_points_for_attacking = 2.0\n"
+ "creature_sight_range = 100.0\n" + "creature_sight_range = 100.0\n"
+ "creature_radius = 20.0\n" + "creature_radius = 20.0\n"
+ "brain_hidden_neurons = 10.0\n" + "brain_hidden_neurons = 20.0\n"
+ "brain_hidden_layers = 2.0\n" + "brain_hidden_layers = 3.0\n"
+ "brain_bias = 0.5\n"; + "brain_bias = 0.5\n";
defaults = Serializer.readSettings(s); defaults = Serializer.readSettings(s);
} }
return defaults; return defaults;
} }
} }

View File

@ -22,7 +22,6 @@ public class Creature extends Element implements Runnable {
private final Brain brain; private final Brain brain;
private final Torso torso; private final Torso torso;
private final Beak beak;
private final ArrayList<BodyPart> bodyParts; private final ArrayList<BodyPart> bodyParts;
private float dir, fitness = 0; private float dir, fitness = 0;
private boolean workerDone = false, killWorker = false; private boolean workerDone = false, killWorker = false;
@ -40,7 +39,7 @@ public class Creature extends Element implements Runnable {
dir = (float) (Math.random() * 2 * Math.PI); dir = (float) (Math.random() * 2 * Math.PI);
bodyParts = new ArrayList<BodyPart>(); bodyParts = new ArrayList<BodyPart>();
bodyParts.add(torso = new Torso(this)); bodyParts.add(torso = new Torso(this));
bodyParts.add(beak = new Beak(0, this)); bodyParts.add(new Beak(0, this));
bodyParts.add(new Eye(5, 0, this)); bodyParts.add(new Eye(5, 0, this));
bodyParts.add(new Movement(this)); bodyParts.add(new Movement(this));
brain = new Brain(howManyInputNeurons(), howManyOutputNeurons(), brain_hidden_layers, brain_hidden_neurons); brain = new Brain(howManyInputNeurons(), howManyOutputNeurons(), brain_hidden_layers, brain_hidden_neurons);
@ -191,6 +190,19 @@ public class Creature extends Element implements Runnable {
} }
} }
public float getDangerLevel() {
int beaks = 0;
float danger = 0;
for (BodyPart b : bodyParts) {
if (b instanceof Beak) {
beaks++;
danger += (((Beak)b).getLength() - Beak.min_length) / Beak.max_length;
}
}
if(beaks == 0) return 0;
return danger / beaks;
}
public Brain getBrain() { public Brain getBrain() {
return brain; return brain;
} }
@ -207,10 +219,6 @@ public class Creature extends Element implements Runnable {
return fitness; return fitness;
} }
public float getBeak() {
return beak.getLength();
}
public Torso getTorso() { public Torso getTorso() {
return torso; return torso;
} }

View File

@ -1,120 +1,120 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package logic.creatures; package logic.creatures;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.mygdx.game.Game; import com.mygdx.game.Game;
import com.mygdx.game.Log; import com.mygdx.game.Log;
import logic.Element; import logic.Element;
import logic.Vegetable; import logic.Vegetable;
/** /**
* *
* @author fazo * @author fazo
*/ */
public class Eye extends BodyPart { public class Eye extends BodyPart {
private Sight sights[]; private Sight sights[];
private int farthest = -1, seen; private int farthest = -1, seen;
private float farthestDistance = 0; private float farthestDistance = 0;
public static float fov = 2, sightRange = 30; public static float fov = 2, sightRange = 30;
public Eye(int nSights, float angle, Creature creature) { public Eye(int nSights, float angle, Creature creature) {
super(6 * nSights, 0, angle, 0.8f, creature); super(6 * nSights, 0, angle, 0.8f, creature);
sights = new Sight[nSights]; sights = new Sight[nSights];
seen = 0; seen = 0;
} }
@Override @Override
public float[] act() { public float[] act() {
float ret[] = new float[inputNeuronsUsed]; float ret[] = new float[inputNeuronsUsed];
int j = 0; int j = 0;
for (int i = 0; i < sights.length; i++) { for (int i = 0; i < sights.length; i++) {
if (i < seen) { if (i < seen) {
// Saw something // Saw something
ret[j] = 1; ret[j] = 1;
ret[j + 1] = sights[i].getElement() instanceof Creature ? 1 : 0; ret[j + 1] = sights[i].getElement() instanceof Creature ? 1 : 0;
ret[j + 2] = sights[i].getDistance() / sightRange; ret[j + 2] = sights[i].getDistance() / sightRange;
ret[j + 3] = sights[i].getAngle(); ret[j + 3] = sights[i].getAngle();
if (sights[i].getElement() instanceof Creature) { if (sights[i].getElement() instanceof Creature) {
ret[i + 4] = ((Creature) sights[i].getElement()).getBeak() / Beak.max_length; ret[i + 4] = ((Creature) sights[i].getElement()).getTorso().getHp() / Torso.max_hp;
ret[i + 5] = ((Creature) sights[i].getElement()).getTorso().getHp() / Torso.max_hp; ret[i + 5] = ((Creature) sights[i].getElement()).getDangerLevel();
} else { } else {
ret[i + 4] = ((Vegetable) sights[i].getElement()).getSize() / Vegetable.default_radius; ret[i + 4] = ((Vegetable) sights[i].getElement()).getSize() / Vegetable.default_radius;
ret[i + 5] = 0; ret[i + 5] = 0;
} }
} else { } else {
// Saw nothing // Saw nothing
for (int z = 0; z < 6; z++) { for (int z = 0; z < 6; z++) {
ret[j + z] = 0; ret[j + z] = 0;
} }
} }
j += 6; j += 6;
} }
seen = 0; seen = 0;
farthest = -1; farthest = -1;
farthestDistance = 0; farthestDistance = 0;
sights = new Sight[sights.length]; sights = new Sight[sights.length];
return ret; return ret;
} }
@Override @Override
public void interactWithElement(Element e, float distance, float angle) { public void interactWithElement(Element e, float distance, float angle) {
if (e != creature && distance < sightRange && (distance < farthestDistance || seen < sights.length) && Math.abs(angle) < fov / 2) { if (e != creature && distance < sightRange && (distance < farthestDistance || seen < sights.length) && Math.abs(angle) < fov / 2) {
if (seen < sights.length) { if (seen < sights.length) {
sights[seen] = new Sight(e, distance, angle); sights[seen] = new Sight(e, distance, angle);
Log.log(Log.DEBUG,"Adding Sight number "+seen); Log.log(Log.DEBUG,"Adding Sight number "+seen);
seen++; seen++;
} else { } else {
Log.log(Log.DEBUG,"Substituting Farthest"); Log.log(Log.DEBUG,"Substituting Farthest");
sights[farthest] = new Sight(e, distance, angle); sights[farthest] = new Sight(e, distance, angle);
farthest = -1; farthest = -1;
} }
for (int i = 0; i < seen; i++) { for (int i = 0; i < seen; i++) {
Sight s = sights[i]; Sight s = sights[i];
if (s.getDistance() > farthestDistance || farthest < 0) { if (s.getDistance() > farthestDistance || farthest < 0) {
farthestDistance = s.getDistance(); farthestDistance = s.getDistance();
farthest = i; farthest = i;
} }
} }
Log.log(Log.DEBUG,"Seen " + seen + "/" + sights.length + ". Farthest is now " + farthest + " at " + farthestDistance); Log.log(Log.DEBUG,"Seen " + seen + "/" + sights.length + ". Farthest is now " + farthest + " at " + farthestDistance);
} }
} }
@Override @Override
protected void draw(ShapeRenderer s, float relX, float relY) { protected void draw(ShapeRenderer s, float relX, float relY) {
// Draw eye // Draw eye
s.setColor(1, 1, 1, 1); s.setColor(1, 1, 1, 1);
s.circle(creature.getX() + relX, creature.getY() + relY, 3); s.circle(creature.getX() + relX, creature.getY() + relY, 3);
// Draw FOV cone // Draw FOV cone
float degrees = fov * 360f / (float) Math.PI; float degrees = fov * 360f / (float) Math.PI;
float orient = (creature.getDirection() + angle) * 180f / (float) Math.PI - degrees / 2; float orient = (creature.getDirection() + angle) * 180f / (float) Math.PI - degrees / 2;
if (Game.get().getWorld().getOptions().getOrDefault("draw_view_cones", 0f) > 0) { if (Game.get().getWorld().getOptions().getOrDefault("draw_view_cones", 0f) > 0) {
s.setColor(0.3f, 0.3f, 0.3f, 1); s.setColor(0.3f, 0.3f, 0.3f, 1);
s.arc((float) relX + creature.getX(), (float) relY + creature.getY(), sightRange, orient, degrees); s.arc((float) relX + creature.getX(), (float) relY + creature.getY(), sightRange, orient, degrees);
} }
// Sight Lines // Sight Lines
float c = 0; float c = 0;
if (Game.get().getWorld().getOptions().getOrDefault("draw_sight_lines", 0f) > 0) { if (Game.get().getWorld().getOptions().getOrDefault("draw_sight_lines", 0f) > 0) {
for (Sight sight : sights) { for (Sight sight : sights) {
if (sight != null) { if (sight != null) {
c = sight.getDistance() / sightRange * 2 + sightRange; c = sight.getDistance() / sightRange * 2 + sightRange;
if (sight.getElement() instanceof Creature) { if (sight.getElement() instanceof Creature) {
s.setColor(c, 0, 0, 1); s.setColor(c, 0, 0, 1);
} else if (sight.getElement() instanceof Vegetable) { } else if (sight.getElement() instanceof Vegetable) {
s.setColor(0, c, 0, 1); s.setColor(0, c, 0, 1);
} }
s.line(relX + creature.getX(), creature.getY() + relY, sight.getElement().getX(), sight.getElement().getY()); s.line(relX + creature.getX(), creature.getY() + relY, sight.getElement().getX(), sight.getElement().getY());
} }
} }
} }
} }
@Override @Override
public void readFromBrain(float[] data) { public void readFromBrain(float[] data) {
} }
} }

View File

@ -19,6 +19,7 @@ import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
@ -71,20 +72,20 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
} }
}); });
/* /*
ArrayList<SortKey> sk = new ArrayList<SortKey>(); ArrayList<SortKey> sk = new ArrayList<SortKey>();
sk.add(new SortKey(0, SortOrder.ASCENDING)); sk.add(new SortKey(0, SortOrder.ASCENDING));
DefaultRowSorter rs = new DefaultRowSorter() {}; DefaultRowSorter rs = new DefaultRowSorter() {};
settingsTable.setRowSorter(rs); settingsTable.setRowSorter(rs);
rs.setSortKeys(sk); rs.setSortKeys(sk);
rs.setComparator(0, new Comparator() { rs.setComparator(0, new Comparator() {
@Override @Override
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
return ((String)o1).compareToIgnoreCase((String)o2); return ((String)o1).compareToIgnoreCase((String)o2);
} }
}); });
rs.sort(); rs.sort();
*/ */
guiUpdater = new Thread() { guiUpdater = new Thread() {
@Override @Override
public void run() { public void run() {
@ -934,16 +935,20 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private void setCreatureList() { private void setCreatureList() {
String list[] = new String[world.getCreatures().size()]; String list[] = new String[world.getCreatures().size()];
int selected = -1; int selected = -1;
for (int i = 0; i < list.length; i++) { try {
if (i >= world.getCreatures().size()) { for (int i = 0; i < list.length; i++) {
return; if (i >= world.getCreatures().size()) {
} return;
list[i] = world.getCreatures().get(i).getBrain().getName() }
+ " - Fitness: " list[i] = world.getCreatures().get(i).getBrain().getName()
+ world.getCreatures().get(i).getFitness(); + " - Fitness: "
if (world.getCreatures().get(i) == world.getSelectedCreature()) { + world.getCreatures().get(i).getFitness();
selected = i; if (world.getCreatures().get(i) == world.getSelectedCreature()) {
selected = i;
}
} }
} catch (IndexOutOfBoundsException ex) {
} catch (ConcurrentModificationException ex) {
} }
creatureList.setListData(list); creatureList.setListData(list);
if (selected >= 0) { if (selected >= 0) {