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

reimplemented mutations, fix #11

This commit is contained in:
Enrico Fasoli 2015-07-14 11:38:37 +02:00
parent 0d8641bf29
commit abb3c96cdf
6 changed files with 331 additions and 39 deletions

View File

@ -92,11 +92,16 @@ public class Game extends ApplicationAdapter {
renderer.begin(ShapeRenderer.ShapeType.Line);
try {
for (Element e : world.getElements()) {
if (e == null) {
// Yeah, the perks of multithreading I guess
continue;
}
try {
e.render(renderer);
} catch (ArrayIndexOutOfBoundsException ex) {
// No idea why it happens, but it's rendering so meh
//Log.log(Log.ERROR, ex+"");
// Render only half the elements because the list gets
// modified by another thread? Who cares, it's a simulation
// not some videogame
}
}
} catch (ConcurrentModificationException ex) {
@ -109,7 +114,7 @@ public class Game extends ApplicationAdapter {
Creature c = world.getSelectedCreature();
renderer.setColor(1, 1, 1, 1);
// Draw selection rectangle
renderer.rect(c.getX() - c.getSize(), c.getY() - c.getSize(), c.getSize()*2, c.getSize()*2);
renderer.rect(c.getX() - c.getSize(), c.getY() - c.getSize(), c.getSize() * 2, c.getSize() * 2);
// Draw brain
overlayRenderer.begin();
c.getBrain().render(overlayRenderer);
@ -132,6 +137,8 @@ public class Game extends ApplicationAdapter {
public void setPaused(boolean paused) {
this.paused = paused;
if(world != null) world.fire(Listener.PAUSED_OR_RESUMED);
if (world != null) {
world.fire(Listener.PAUSED_OR_RESUMED);
}
}
}

View File

@ -24,6 +24,7 @@ import java.util.logging.Logger;
public class World implements Runnable {
private int width, height, nPlants, creatPerGen;
private float nMutatedBrains = 0.2f, nMutatedNeurons = 0.5f, nMutatedConnections = 0.5f, mutationFactor = 1f;
private int generation = 1;
private boolean multithreading, cmdLaunchNewGen = false, cmdRestart = false;
private int fpsLimit, fps = 0;
@ -229,7 +230,9 @@ public class World implements Runnable {
Logger.getLogger(World.class.getName()).log(Level.SEVERE, null, ex);
}
Creature ne = spawnCreature(n);
ne.getBrain().mutate(0.05f); // mutate children
if (Math.random() <= nMutatedBrains) {
ne.getBrain().mutate(nMutatedNeurons, nMutatedConnections, mutationFactor);
}
}
graveyard.clear();
fire(Listener.CREATURE_LIST_CHANGED);
@ -253,6 +256,10 @@ public class World implements Runnable {
Creature.fov = Math.round(options.getOrDefault("creature_fov", (float) Math.PI / 2.5f));
Creature.sightRange = Math.round(options.getOrDefault("creature_sight_range", 100f));
Creature.hpDecay = options.getOrDefault("creature_hp_decay", 0.5f);
nMutatedBrains = options.getOrDefault("nMutatedBrains", 0.2f);
nMutatedNeurons = options.getOrDefault("nMutatedNeurons", 0.5f);
nMutatedConnections = options.getOrDefault("nMutatedConnections", 0.5f);
mutationFactor = options.getOrDefault("nMutationFactor", 1f);
}
private Element spawn(boolean isCreature, float[][][] brainMap) {

View File

@ -104,7 +104,7 @@ public class Brain {
// Draw neuron links
float[] links = neurons[i][j].getWeights();
for (int f = 0; f < links.length; f++) {
s.setColor(links[f] < 0 ? links[f]/2 * -1 : 0, links[f] > 0 ? links[f]/2 : 0, 0, 1);
s.setColor(links[f] < 0 ? links[f] / 2 * -1 : 0, links[f] > 0 ? links[f] / 2 : 0, 0, 1);
s.line(i * sepX + offset, j * sepY + offset, (i - 1) * sepX + offset, f * sepY + offset);
}
// Draw neuron
@ -182,16 +182,22 @@ public class Brain {
* Get a map of this brain's mind.. with a mutation
*
* @param mutationFactor the higher this number, the bigger the mutation
* @param connectionMutationProbability the probability that determines how
* many connections mutate in a neuron (from 0 to 1)
* @param mutationProbability the higher this number the higher the amount
* of mutated neurons (range: from 0 to 1)
* @return a mutated brain map of this brain's mind
*/
public float[][][] getMutatedMap(float mutationFactor) {
public float[][][] getMutatedMap(float mutationProbability, float connectionMutationProbability, float mutationFactor) {
float[][][] res = new float[neurons.length - 1][][];
for (int i = 1; i < neurons.length; i++) // layers (skip input layer)
{
res[i - 1] = new float[neurons[i].length][];
for (int j = 0; j < neurons[i].length; j++) // neurons per layer
{
res[i - 1][j] = neurons[i][j].mutate(mutationFactor);
if (Math.random() <= mutationProbability) {
res[i - 1][j] = neurons[i][j].getMutatedWeights(connectionMutationProbability, mutationFactor);
}
}
}
return res;
@ -200,14 +206,20 @@ public class Brain {
/**
* Apply a mutation to this brain
*
* @param connectionMutationProbability the probability that determines how
* many connections mutate in a neuron (from 0 to 1)
* @param mutationProbability the higher this number the higher the amount
* of mutated neurons (range: from 0 to 1)
* @param mutationFactor the higher this number, the bigger the mutation
*/
public void mutate(float mutationFactor) {
public void mutate(float mutationProbability, float connectionMutationProbability, float mutationFactor) {
for (int i = 1; i < neurons.length; i++) // layers (skip input layer)
{
for (int j = 0; j < neurons[i].length; j++) // neurons per layer
{
neurons[i][j].setWeights(neurons[i][j].mutate(mutationFactor));
if (Math.random() <= mutationProbability) {
neurons[i][j].setWeights(neurons[i][j].getMutatedWeights(connectionMutationProbability, mutationFactor));
}
}
}
}

View File

@ -77,10 +77,14 @@ public class Neuron {
return res;
}
public float[] mutate(float mutationFactor) {
public float[] getMutatedWeights(float mutationProbability, float mutationFactor) {
float[] mutatedWeights = new float[weights.length];
for (int i = 0; i < weights.length; i++) {
mutatedWeights[i] = weights[i] + mutationFactor - mutationFactor / 2;
if (Math.random() <= mutationProbability) {
mutatedWeights[i] = weights[i] + (float) (Math.random() * mutationFactor) - mutationFactor / 2;
} else {
mutatedWeights[i] = weights[i];
}
}
return mutatedWeights;
}

View File

@ -87,10 +87,10 @@
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="AIrium"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[530, 450]"/>
<Dimension value="[700, 700]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[530, 450]"/>
<Dimension value="[700, 700]"/>
</Property>
</Properties>
<SyntheticProperties>
@ -168,13 +168,13 @@
<Component id="logLevelBox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="jScrollPane1" alignment="0" pref="525" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="695" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" pref="340" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="490" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
@ -269,15 +269,9 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="drawViewCones" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="drawSightLines" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@ -349,7 +343,7 @@
<Component id="enableCorpsesCheckbox" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="24" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
@ -362,6 +356,44 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="currentMaxTicks" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel11" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="nMutatedBrainsSlider" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="currentNMutatedBrains" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel13" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="nMutatedNeuronsSlider" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="currentNMutatedNeurons" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel15" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mutationFactorSlider" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="currentMutationFactor" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel12" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="nMutatedConnectionsSlider" min="-2" pref="490" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="currentNMutatedConnections" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="drawViewCones" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="drawSightLines" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -436,11 +468,35 @@
<Component id="currentMaxTicks" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="nMutatedBrainsSlider" max="32767" attributes="0"/>
<Component id="currentNMutatedBrains" alignment="0" max="32767" attributes="0"/>
<Component id="jLabel11" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="nMutatedNeuronsSlider" max="32767" attributes="0"/>
<Component id="currentNMutatedNeurons" alignment="0" max="32767" attributes="0"/>
<Component id="jLabel13" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="currentNMutatedConnections" max="32767" attributes="0"/>
<Component id="jLabel12" alignment="0" max="32767" attributes="0"/>
<Component id="nMutatedConnectionsSlider" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="mutationFactorSlider" min="-2" max="-2" attributes="0"/>
<Component id="jLabel15" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="currentMutationFactor" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="drawViewCones" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="drawSightLines" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="19" max="32767" attributes="0"/>
<EmptySpace pref="41" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="pauseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
@ -684,6 +740,74 @@
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="drawSightLinesStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel11">
<Properties>
<Property name="text" type="java.lang.String" value="Probability of children mutation"/>
</Properties>
</Component>
<Component class="javax.swing.JSlider" name="nMutatedBrainsSlider">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="nMutatedBrainsSliderStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="currentNMutatedBrains">
<Properties>
<Property name="text" type="java.lang.String" value="10%"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel13">
<Properties>
<Property name="text" type="java.lang.String" value="Number of mutated neurons"/>
</Properties>
</Component>
<Component class="javax.swing.JSlider" name="nMutatedNeuronsSlider">
<Properties>
<Property name="value" type="int" value="20"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="nMutatedNeuronsSliderStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="currentNMutatedNeurons">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel14"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel15">
<Properties>
<Property name="text" type="java.lang.String" value="Mutation Factor"/>
</Properties>
</Component>
<Component class="javax.swing.JSlider" name="mutationFactorSlider">
<Properties>
<Property name="majorTickSpacing" type="int" value="1"/>
<Property name="maximum" type="int" value="200"/>
<Property name="value" type="int" value="100"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="mutationFactorSliderStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="currentMutationFactor">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel16"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel12">
<Properties>
<Property name="text" type="java.lang.String" value="Number of mutated synapsis"/>
</Properties>
</Component>
<Component class="javax.swing.JSlider" name="nMutatedConnectionsSlider">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="nMutatedConnectionsSliderStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="currentNMutatedConnections">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel14"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>

View File

@ -117,6 +117,18 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
jButton1 = new javax.swing.JButton();
drawViewCones = new javax.swing.JCheckBox();
drawSightLines = new javax.swing.JCheckBox();
jLabel11 = new javax.swing.JLabel();
nMutatedBrainsSlider = new javax.swing.JSlider();
currentNMutatedBrains = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
nMutatedNeuronsSlider = new javax.swing.JSlider();
currentNMutatedNeurons = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
mutationFactorSlider = new javax.swing.JSlider();
currentMutationFactor = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
nMutatedConnectionsSlider = new javax.swing.JSlider();
currentNMutatedConnections = new javax.swing.JLabel();
status = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
@ -130,8 +142,8 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("AIrium");
setMinimumSize(new java.awt.Dimension(530, 450));
setPreferredSize(new java.awt.Dimension(530, 450));
setMinimumSize(new java.awt.Dimension(700, 700));
setPreferredSize(new java.awt.Dimension(700, 700));
logTextArea.setEditable(false);
logTextArea.setColumns(20);
@ -161,12 +173,12 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(logLevelBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE)
);
logPaneLayout.setVerticalGroup(
logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(logPaneLayout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)
.addGap(10, 10, 10)
.addGroup(logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
@ -354,6 +366,50 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
}
});
jLabel11.setText("Probability of children mutation");
nMutatedBrainsSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
nMutatedBrainsSliderStateChanged(evt);
}
});
currentNMutatedBrains.setText("10%");
jLabel13.setText("Number of mutated neurons");
nMutatedNeuronsSlider.setValue(20);
nMutatedNeuronsSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
nMutatedNeuronsSliderStateChanged(evt);
}
});
currentNMutatedNeurons.setText("jLabel14");
jLabel15.setText("Mutation Factor");
mutationFactorSlider.setMajorTickSpacing(1);
mutationFactorSlider.setMaximum(200);
mutationFactorSlider.setValue(100);
mutationFactorSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
mutationFactorSliderStateChanged(evt);
}
});
currentMutationFactor.setText("jLabel16");
jLabel12.setText("Number of mutated synapsis");
nMutatedConnectionsSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
nMutatedConnectionsSliderStateChanged(evt);
}
});
currentNMutatedConnections.setText("jLabel14");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
@ -361,11 +417,6 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(drawViewCones)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(drawSightLines)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@ -426,7 +477,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addComponent(multithreadingCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(enableCorpsesCheckbox)))
.addGap(0, 24, Short.MAX_VALUE)))
.addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentHpDecay))
.addGroup(jPanel1Layout.createSequentialGroup()
@ -434,7 +485,38 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(maxTicksSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentMaxTicks)))
.addComponent(currentMaxTicks))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNMutatedBrains))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNMutatedNeurons))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mutationFactorSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentMutationFactor))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNMutatedConnections))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(drawViewCones)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(drawSightLines)))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
@ -493,10 +575,30 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addComponent(maxTicksSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(currentMaxTicks, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(currentNMutatedBrains, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(currentNMutatedNeurons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(currentNMutatedConnections, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mutationFactorSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(currentMutationFactor, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(drawViewCones)
.addComponent(drawSightLines))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(pauseButton)
.addComponent(jButton1))
@ -709,11 +811,19 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
options.put("creature_sight_range", (float) sightRangeSlider.getValue());
options.put("creature_hp_decay", (float) hpDecaySlider.getValue() / 1000);
options.put("max_ticks", (float) maxTicksSlider.getValue());
options.put("draw_view_cones",drawViewCones.isSelected()?1f:0);
options.put("draw_sight_lines",drawSightLines.isSelected()?1f:0);
options.put("draw_view_cones", drawViewCones.isSelected() ? 1f : 0);
options.put("draw_sight_lines", drawSightLines.isSelected() ? 1f : 0);
currentMaxTicks.setText(maxTicksSlider.getValue() + "");
currentHpDecay.setText(hpDecaySlider.getValue() / 1000f + "");
currentSightRange.setText(sightRangeSlider.getValue() + "");
options.put("nMutatedBrains", (float) nMutatedBrainsSlider.getValue()/100);
currentNMutatedBrains.setText(String.format("%.2f", (float) nMutatedBrainsSlider.getValue()/100)+"%");
options.put("nMutatedNeurons", (float) nMutatedNeuronsSlider.getValue()/100);
currentNMutatedNeurons.setText(String.format("%.2f", (float) nMutatedNeuronsSlider.getValue()/100)+"%");
options.put("nMutatedConnections", (float) nMutatedConnectionsSlider.getValue()/100);
currentNMutatedConnections.setText(String.format("%.2f", (float) nMutatedConnectionsSlider.getValue()/100)+"%");
options.put("mutationFactor", (float) mutationFactorSlider.getValue()/100);
currentMutationFactor.setText(String.format("%.2f", (float) mutationFactorSlider.getValue()/100));
if (game != null) {
game.getWorld().reloadOptions();
}
@ -831,6 +941,22 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
updateSettings();
}//GEN-LAST:event_drawSightLinesStateChanged
private void nMutatedNeuronsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nMutatedNeuronsSliderStateChanged
updateSettings();
}//GEN-LAST:event_nMutatedNeuronsSliderStateChanged
private void mutationFactorSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_mutationFactorSliderStateChanged
updateSettings();
}//GEN-LAST:event_mutationFactorSliderStateChanged
private void nMutatedBrainsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nMutatedBrainsSliderStateChanged
updateSettings();
}//GEN-LAST:event_nMutatedBrainsSliderStateChanged
private void nMutatedConnectionsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nMutatedConnectionsSliderStateChanged
updateSettings();
}//GEN-LAST:event_nMutatedConnectionsSliderStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel container;
private javax.swing.JSlider corpseDecaySlider;
@ -839,7 +965,11 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private javax.swing.JLabel currentFpsLimit;
private javax.swing.JLabel currentHpDecay;
private javax.swing.JLabel currentMaxTicks;
private javax.swing.JLabel currentMutationFactor;
private javax.swing.JLabel currentNCreatures;
private javax.swing.JLabel currentNMutatedBrains;
private javax.swing.JLabel currentNMutatedConnections;
private javax.swing.JLabel currentNMutatedNeurons;
private javax.swing.JLabel currentNPlants;
private javax.swing.JLabel currentSightRange;
private javax.swing.JLabel currentTopSize;
@ -853,6 +983,10 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
@ -875,7 +1009,11 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private javax.swing.JSlider maxTicksSlider;
private javax.swing.JMenuBar menuBar;
private javax.swing.JCheckBox multithreadingCheckbox;
private javax.swing.JSlider mutationFactorSlider;
private javax.swing.JSlider nCreaturesSlider;
private javax.swing.JSlider nMutatedBrainsSlider;
private javax.swing.JSlider nMutatedConnectionsSlider;
private javax.swing.JSlider nMutatedNeuronsSlider;
private javax.swing.JSlider nPlantsSlider;
private javax.swing.JToggleButton pauseButton;
private javax.swing.JMenuItem pauseMenuButton;