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.math.Vector3;
import java.util.ConcurrentModificationException;
import java.util.Map;
import logic.creatures.Creature;
import logic.Element;
import logic.World;

View File

@ -176,14 +176,14 @@ public class Serializer {
+ "draw_view_cones = 0.0\n"
+ "world_width = 2000.0\n"
+ "world_height = 2000.0\n"
+ "number_of_plants = 700.0\n"
+ "number_of_plants = 200.0\n"
+ "nMutatedNeurons = 0.2\n"
+ "enable_corpses = 0.0\n"
+ "nMutatedBrains = 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"
+ "vegetable_size = 5\n"
+ "vegetable_size = 20\n"
+ "creature_max_hp = 100\n"
+ "creature_fov = 1.5\n"
+ "creature_hp_decay = 0.5\n"
@ -194,8 +194,8 @@ public class Serializer {
+ "creature_points_for_attacking = 2.0\n"
+ "creature_sight_range = 100.0\n"
+ "creature_radius = 20.0\n"
+ "brain_hidden_neurons = 10.0\n"
+ "brain_hidden_layers = 2.0\n"
+ "brain_hidden_neurons = 20.0\n"
+ "brain_hidden_layers = 3.0\n"
+ "brain_bias = 0.5\n";
defaults = Serializer.readSettings(s);
}

View File

@ -22,7 +22,6 @@ public class Creature extends Element implements Runnable {
private final Brain brain;
private final Torso torso;
private final Beak beak;
private final ArrayList<BodyPart> bodyParts;
private float dir, fitness = 0;
private boolean workerDone = false, killWorker = false;
@ -40,7 +39,7 @@ public class Creature extends Element implements Runnable {
dir = (float) (Math.random() * 2 * Math.PI);
bodyParts = new ArrayList<BodyPart>();
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 Movement(this));
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() {
return brain;
}
@ -207,10 +219,6 @@ public class Creature extends Element implements Runnable {
return fitness;
}
public float getBeak() {
return beak.getLength();
}
public Torso getTorso() {
return torso;
}

View File

@ -40,8 +40,8 @@ public class Eye extends BodyPart {
ret[j + 2] = sights[i].getDistance() / sightRange;
ret[j + 3] = sights[i].getAngle();
if (sights[i].getElement() instanceof Creature) {
ret[i + 4] = ((Creature) sights[i].getElement()).getBeak() / Beak.max_length;
ret[i + 5] = ((Creature) sights[i].getElement()).getTorso().getHp() / Torso.max_hp;
ret[i + 4] = ((Creature) sights[i].getElement()).getTorso().getHp() / Torso.max_hp;
ret[i + 5] = ((Creature) sights[i].getElement()).getDangerLevel();
} else {
ret[i + 4] = ((Vegetable) sights[i].getElement()).getSize() / Vegetable.default_radius;
ret[i + 5] = 0;

View File

@ -19,6 +19,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
@ -934,6 +935,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private void setCreatureList() {
String list[] = new String[world.getCreatures().size()];
int selected = -1;
try {
for (int i = 0; i < list.length; i++) {
if (i >= world.getCreatures().size()) {
return;
@ -945,6 +947,9 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
selected = i;
}
}
} catch (IndexOutOfBoundsException ex) {
} catch (ConcurrentModificationException ex) {
}
creatureList.setListData(list);
if (selected >= 0) {
creatureList.setSelectedIndex(selected);