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

loading settings almost works

This commit is contained in:
Enrico Fasoli 2015-08-06 13:22:23 +02:00
parent cae72163a4
commit 28029c2a66
3 changed files with 266 additions and 98 deletions

View File

@ -7,6 +7,7 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -34,19 +35,50 @@ public class Serializer {
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) {
String a = "# Settings file for use with AIrium.\n"
+ "# More information at http://github.com/fazo96/AIrium";
for (Object o : options.entrySet().toArray()) {
Map.Entry<String, Float> e = (Map.Entry<String, Float>) o;
a += e.getKey() + " = " + e.getValue() + "\n";
}
return a;
}
public static void readSettings(String fileContent, Map<String, Float> m) {
int line = 0;
for (String s : fileContent.split("\n")) {
line++;
if (s.startsWith("#")) {
// Skip comment
continue;
}
String[] ss = s.trim().split(" = ");
try {
if (ss.length != 2) {
throw new Exception("Invalid string at line " + line);
}
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()));
} catch (Exception e) {
Log.log(Log.ERROR, e.getMessage());
}
}
}
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)
@ -64,7 +96,7 @@ public class Serializer {
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:\n"+s); 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("#")) {
@ -91,8 +123,8 @@ public class Serializer {
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.INFO, "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 "
@ -101,11 +133,12 @@ public class Serializer {
} }
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.INFO,"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.INFO, "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.");
return brainMap; return brainMap;
} }
} }

View File

@ -225,7 +225,7 @@
</Component> </Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="jPanel1"> <Container class="javax.swing.JPanel" name="settingsPanel">
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Settings"> <JTabbedPaneConstraints tabName="Settings">
@ -302,6 +302,10 @@
<Component id="pauseButton" min="-2" max="-2" attributes="0"/> <Component id="pauseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/> <Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="saveSettingsBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="loadSettingsBtn" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="toggleFPSLimitCheckbox" min="-2" max="-2" attributes="0"/> <Component id="toggleFPSLimitCheckbox" min="-2" max="-2" attributes="0"/>
@ -468,6 +472,8 @@
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="pauseButton" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="pauseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="saveSettingsBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="loadSettingsBtn" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -776,9 +782,25 @@
<Property name="text" type="java.lang.String" value="jLabel14"/> <Property name="text" type="java.lang.String" value="jLabel14"/>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JButton" name="saveSettingsBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Save Settings"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveSettingsBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="loadSettingsBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Load Settings"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadSettingsBtnActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="jPanel3"> <Container class="javax.swing.JPanel" name="creaturesPanel">
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Creatures"> <JTabbedPaneConstraints tabName="Creatures">
@ -796,7 +818,7 @@
<Component id="saveBrainBtn" min="-2" max="-2" attributes="0"/> <Component id="saveBrainBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="loadBrainBtn" min="-2" max="-2" attributes="0"/> <Component id="loadBrainBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="587" max="32767" attributes="0"/> <EmptySpace pref="477" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -839,7 +861,7 @@
</Container> </Container>
<Component class="javax.swing.JButton" name="saveBrainBtn"> <Component class="javax.swing.JButton" name="saveBrainBtn">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Save"/> <Property name="text" type="java.lang.String" value="Save Creature"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveBrainBtnActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveBrainBtnActionPerformed"/>
@ -847,7 +869,7 @@
</Component> </Component>
<Component class="javax.swing.JButton" name="loadBrainBtn"> <Component class="javax.swing.JButton" name="loadBrainBtn">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Load"/> <Property name="text" type="java.lang.String" value="Load Creature"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadBrainBtnActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadBrainBtnActionPerformed"/>

View File

@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javafx.stage.FileChooser;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import logic.Creature; import logic.Creature;
@ -35,7 +34,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private Game game; private Game game;
private LwjglApplication app; private LwjglApplication app;
private boolean shouldUpdateGUI = false; private boolean shouldUpdateGUI = false;
private Thread guiUpdater; private final Thread guiUpdater;
private Map<String, Float> options; private Map<String, Float> options;
/** /**
@ -85,7 +84,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
logTextArea = new javax.swing.JTextArea(); logTextArea = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
logLevelBox = new javax.swing.JComboBox(); logLevelBox = new javax.swing.JComboBox();
jPanel1 = new javax.swing.JPanel(); settingsPanel = new javax.swing.JPanel();
fpsLimitSlider = new javax.swing.JSlider(); fpsLimitSlider = new javax.swing.JSlider();
jLabel3 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel();
toggleFPSLimitCheckbox = new javax.swing.JCheckBox(); toggleFPSLimitCheckbox = new javax.swing.JCheckBox();
@ -132,7 +131,9 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
jLabel12 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel();
nMutatedConnectionsSlider = new javax.swing.JSlider(); nMutatedConnectionsSlider = new javax.swing.JSlider();
currentNMutatedConnections = new javax.swing.JLabel(); currentNMutatedConnections = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel(); saveSettingsBtn = new javax.swing.JButton();
loadSettingsBtn = new javax.swing.JButton();
creaturesPanel = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane(); jScrollPane2 = new javax.swing.JScrollPane();
creatureList = new javax.swing.JList(); creatureList = new javax.swing.JList();
saveBrainBtn = new javax.swing.JButton(); saveBrainBtn = new javax.swing.JButton();
@ -402,68 +403,86 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
currentNMutatedConnections.setText("jLabel14"); currentNMutatedConnections.setText("jLabel14");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); saveSettingsBtn.setText("Save Settings");
jPanel1.setLayout(jPanel1Layout); saveSettingsBtn.addActionListener(new java.awt.event.ActionListener() {
jPanel1Layout.setHorizontalGroup( public void actionPerformed(java.awt.event.ActionEvent evt) {
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) saveSettingsBtnActionPerformed(evt);
.addGroup(jPanel1Layout.createSequentialGroup() }
});
loadSettingsBtn.setText("Load Settings");
loadSettingsBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadSettingsBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
settingsPanel.setLayout(settingsPanelLayout);
settingsPanelLayout.setHorizontalGroup(
settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(settingsPanelLayout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel3) .addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fpsLimitSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(fpsLimitSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentFpsLimit)) .addComponent(currentFpsLimit))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel4) .addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nCreaturesSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nCreaturesSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNCreatures)) .addComponent(currentNCreatures))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel5) .addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nPlantsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nPlantsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNPlants)) .addComponent(currentNPlants))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel7) .addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(worldSizeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(worldSizeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentWorldSize)) .addComponent(currentWorldSize))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel2) .addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(corpseDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(corpseDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentCorpseDecay)) .addComponent(currentCorpseDecay))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel6) .addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(topSizeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(topSizeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentTopSize)) .addComponent(currentTopSize))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel8) .addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sightRangeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(sightRangeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentSightRange)) .addComponent(currentSightRange))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel9) .addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(hpDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(hpDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(pauseButton) .addComponent(pauseButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)) .addComponent(jButton1)
.addGroup(jPanel1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveSettingsBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(loadSettingsBtn))
.addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(toggleFPSLimitCheckbox) .addComponent(toggleFPSLimitCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(multithreadingCheckbox) .addComponent(multithreadingCheckbox)
@ -472,58 +491,58 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addGap(0, 0, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentHpDecay)) .addComponent(currentHpDecay))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel10) .addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(maxTicksSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(maxTicksSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentMaxTicks)) .addComponent(currentMaxTicks))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel11) .addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNMutatedBrains)) .addComponent(currentNMutatedBrains))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel13) .addComponent(jLabel13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNMutatedNeurons)) .addComponent(currentNMutatedNeurons))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel15) .addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mutationFactorSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(mutationFactorSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentMutationFactor)) .addComponent(currentMutationFactor))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(jLabel12) .addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(currentNMutatedConnections)) .addComponent(currentNMutatedConnections))
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addComponent(drawViewCones) .addComponent(drawViewCones)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(drawSightLines))) .addComponent(drawSightLines)))
.addGap(0, 0, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
); );
jPanel1Layout.setVerticalGroup( settingsPanelLayout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(fpsLimitSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(fpsLimitSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(currentFpsLimit, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(currentFpsLimit, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(settingsPanelLayout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(toggleFPSLimitCheckbox) .addComponent(toggleFPSLimitCheckbox)
.addComponent(multithreadingCheckbox) .addComponent(multithreadingCheckbox)
.addComponent(enableCorpsesCheckbox)) .addComponent(enableCorpsesCheckbox))
@ -532,72 +551,74 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addComponent(currentNCreatures, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(currentNCreatures, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(nCreaturesSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(nCreaturesSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(currentNPlants, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentNPlants, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nPlantsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(nPlantsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(worldSizeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(worldSizeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(currentWorldSize, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(currentWorldSize, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(corpseDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(corpseDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(currentCorpseDecay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(currentCorpseDecay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(topSizeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(topSizeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(currentTopSize, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(currentTopSize, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(sightRangeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(sightRangeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(currentSightRange, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(currentSightRange, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(hpDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(hpDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(currentHpDecay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(currentHpDecay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(maxTicksSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .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)) .addComponent(currentMaxTicks, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .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(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)) .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .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(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)) .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(currentNMutatedConnections, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .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(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)) .addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mutationFactorSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .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(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)) .addComponent(currentMutationFactor, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(drawViewCones) .addComponent(drawViewCones)
.addComponent(drawSightLines)) .addComponent(drawSightLines))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(pauseButton) .addComponent(pauseButton)
.addComponent(jButton1)) .addComponent(jButton1)
.addComponent(saveSettingsBtn)
.addComponent(loadSettingsBtn))
.addContainerGap()) .addContainerGap())
); );
tabs.addTab("Settings", jPanel1); tabs.addTab("Settings", settingsPanel);
creatureList.setModel(new javax.swing.AbstractListModel() { creatureList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "No creatures" }; String[] strings = { "No creatures" };
@ -612,44 +633,44 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
}); });
jScrollPane2.setViewportView(creatureList); jScrollPane2.setViewportView(creatureList);
saveBrainBtn.setText("Save"); saveBrainBtn.setText("Save Creature");
saveBrainBtn.addActionListener(new java.awt.event.ActionListener() { saveBrainBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
saveBrainBtnActionPerformed(evt); saveBrainBtnActionPerformed(evt);
} }
}); });
loadBrainBtn.setText("Load"); loadBrainBtn.setText("Load Creature");
loadBrainBtn.addActionListener(new java.awt.event.ActionListener() { loadBrainBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
loadBrainBtnActionPerformed(evt); loadBrainBtnActionPerformed(evt);
} }
}); });
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); javax.swing.GroupLayout creaturesPanelLayout = new javax.swing.GroupLayout(creaturesPanel);
jPanel3.setLayout(jPanel3Layout); creaturesPanel.setLayout(creaturesPanelLayout);
jPanel3Layout.setHorizontalGroup( creaturesPanelLayout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2) .addComponent(jScrollPane2)
.addGroup(jPanel3Layout.createSequentialGroup() .addGroup(creaturesPanelLayout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(saveBrainBtn) .addComponent(saveBrainBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(loadBrainBtn) .addComponent(loadBrainBtn)
.addContainerGap(587, Short.MAX_VALUE)) .addContainerGap(477, Short.MAX_VALUE))
); );
jPanel3Layout.setVerticalGroup( creaturesPanelLayout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup() .addGroup(creaturesPanelLayout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveBrainBtn) .addComponent(saveBrainBtn)
.addComponent(loadBrainBtn)) .addComponent(loadBrainBtn))
.addContainerGap()) .addContainerGap())
); );
tabs.addTab("Creatures", jPanel3); tabs.addTab("Creatures", creaturesPanel);
status.setText("Simulation stopped"); status.setText("Simulation stopped");
@ -757,7 +778,6 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
} }
game.getWorld().restart(); game.getWorld().restart();
game.setPaused(false); game.setPaused(false);
updateGUI();
} else { } else {
// Start new // Start new
LwjglApplicationConfiguration.disableAudio = true; LwjglApplicationConfiguration.disableAudio = true;
@ -772,9 +792,14 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
game.getWorld().addListener(this); game.getWorld().addListener(this);
setCreatureList(); setCreatureList();
} }
updateGUI();
}//GEN-LAST:event_startButtonActionPerformed }//GEN-LAST:event_startButtonActionPerformed
@Override @Override
public void onLog(int level, String msg) { public void onLog(int level, String msg) {
if (level == Log.ERROR) {
JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);
}
logTextArea.append(msg + "\n"); logTextArea.append(msg + "\n");
setScrollBarToTheBottom(); setScrollBarToTheBottom();
} }
@ -785,10 +810,19 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
guiUpdater.interrupt(); guiUpdater.interrupt();
} }
public void enableControlButtons(boolean yn) {
pauseButton.setEnabled(yn);
pauseMenuButton.setEnabled(yn);
saveBrainBtn.setEnabled(yn);
loadBrainBtn.setEnabled(yn);
}
public void updateGUI() { public void updateGUI() {
if (game == null) { if (game == null) {
enableControlButtons(false);
return; return;
} }
enableControlButtons(true);
status.setText("Generation: " + game.getWorld().getGeneration() + " FPS: " + game.getWorld().getFps()); status.setText("Generation: " + game.getWorld().getGeneration() + " FPS: " + game.getWorld().getFps());
if (game.isPaused()) { if (game.isPaused()) {
pauseButton.setSelected(true); pauseButton.setSelected(true);
@ -804,13 +838,20 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private void setCreatureList() { private void setCreatureList() {
String list[] = new String[game.getWorld().getCreatures().size()]; String list[] = new String[game.getWorld().getCreatures().size()];
int selected = -1;
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (i >= game.getWorld().getCreatures().size()) { if (i >= game.getWorld().getCreatures().size()) {
return; return;
} }
list[i] = "Fitness: " + game.getWorld().getCreatures().get(i).getFitness(); list[i] = "Fitness: " + game.getWorld().getCreatures().get(i).getFitness();
if (game.getWorld().getCreatures().get(i) == game.getWorld().getSelectedCreature()) {
selected = i;
}
} }
creatureList.setListData(list); creatureList.setListData(list);
if (selected >= 0) {
creatureList.setSelectedIndex(selected);
}
} }
private void resetDefaultSettings() { private void resetDefaultSettings() {
@ -831,6 +872,9 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
updateSettings(); updateSettings();
} }
/**
* Adjusts settings using values from the UI
*/
private void updateSettings() { private void updateSettings() {
currentFpsLimit.setText("" + fpsLimitSlider.getValue()); currentFpsLimit.setText("" + fpsLimitSlider.getValue());
if (toggleFPSLimitCheckbox.isSelected()) { if (toggleFPSLimitCheckbox.isSelected()) {
@ -987,6 +1031,24 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
updateSettings(); updateSettings();
}//GEN-LAST:event_nMutatedConnectionsSliderStateChanged }//GEN-LAST:event_nMutatedConnectionsSliderStateChanged
private File saveDialog() {
JFileChooser fc = new JFileChooser();
File f = null;
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
f = fc.getSelectedFile();
}
return f;
}
private File loadDialog() {
JFileChooser fc = new JFileChooser();
File f = null;
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
f = fc.getSelectedFile();
}
return f;
}
private void creatureListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_creatureListValueChanged private void creatureListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_creatureListValueChanged
if (game == null) { if (game == null) {
creatureList.setSelectedIndex(-1); creatureList.setSelectedIndex(-1);
@ -1002,38 +1064,88 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
}//GEN-LAST:event_creatureListValueChanged }//GEN-LAST:event_creatureListValueChanged
private void saveBrainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBrainBtnActionPerformed private void saveBrainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBrainBtnActionPerformed
game.setPaused(true); if (game != null) {
game.setPaused(true);
}
updateGUI(); updateGUI();
if (game.getWorld().getSelectedCreature() == null) { if (game.getWorld().getSelectedCreature() == null) {
JOptionPane.showMessageDialog(this, "Please select a creature first"); JOptionPane.showMessageDialog(this, "Please select a creature first");
return; return;
} }
JFileChooser fc = new JFileChooser(); File f = saveDialog();
File f = null; if (f == null) {
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { return;
f = fc.getSelectedFile(); }
} else return;
Serializer.saveToFile(f, Serializer.serializeBrain(game.getWorld().getSelectedCreature().getBrain().getMap())); Serializer.saveToFile(f, Serializer.serializeBrain(game.getWorld().getSelectedCreature().getBrain().getMap()));
}//GEN-LAST:event_saveBrainBtnActionPerformed }//GEN-LAST:event_saveBrainBtnActionPerformed
private void loadBrainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadBrainBtnActionPerformed private void loadBrainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadBrainBtnActionPerformed
game.setPaused(true); if (game != null) {
game.setPaused(true);
}
updateGUI(); updateGUI();
JFileChooser fc = new JFileChooser(); File f = loadDialog();
File f = null;
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
f = fc.getSelectedFile();
} else return;
float map[][][] = Serializer.loadBrain(Serializer.loadFromFile(f)); float map[][][] = Serializer.loadBrain(Serializer.loadFromFile(f));
Creature c = (Creature) game.getWorld().spawnCreature(map); Creature c = (Creature) game.getWorld().spawnCreature(map);
game.getWorld().selectCreature(c); game.getWorld().selectCreature(c);
updateGUI(); updateGUI();
}//GEN-LAST:event_loadBrainBtnActionPerformed }//GEN-LAST:event_loadBrainBtnActionPerformed
private void saveSettingsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSettingsBtnActionPerformed
if (game != null) {
game.setPaused(true);
}
updateGUI();
File f = saveDialog();
if (f == null) {
return;
}
String settings = Serializer.serializeSettings(options);
Serializer.saveToFile(f, settings);
}//GEN-LAST:event_saveSettingsBtnActionPerformed
private void loadSettingsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSettingsBtnActionPerformed
if (game != null) {
game.setPaused(true);
}
updateGUI();
File f = loadDialog();
if (f == null) {
return;
}
Serializer.readSettings(Serializer.loadFromFile(f), options);
updateSettingsUI();
}//GEN-LAST:event_loadSettingsBtnActionPerformed
/**
* Reads settings and adjusts UI sliders.
*/
private void updateSettingsUI() {
fpsLimitSlider.setValue(options.get("fps_limit").intValue());
multithreadingCheckbox.setSelected(options.get("enable_multithreading") > 0f);
nCreaturesSlider.setValue(options.get("number_of_creatures").intValue());
topSizeSlider.setMaximum(nCreaturesSlider.getValue());
nPlantsSlider.setValue(options.get("number_of_plants").intValue());
corpseDecaySlider.setValue((int) (options.get("corpse_decay_rate") * 1000));
enableCorpsesCheckbox.setSelected(options.get("enable_corpses") > 0f);
worldSizeSlider.setValue(options.get("world_height").intValue());
topSizeSlider.setValue(options.get("parents_count").intValue());
sightRangeSlider.setValue(options.get("creature_sight_range").intValue());
hpDecaySlider.setValue((int) (options.get("creature_hp_decay") * 1000));
maxTicksSlider.setValue(options.get("max_ticks").intValue());
drawViewCones.setSelected(options.get("draw_view_cones") > 0f);
drawSightLines.setSelected(options.get("draw_sight_lines") > 0f);
nMutatedBrainsSlider.setValue((int) (options.get("nMutatedBrains").intValue() * 100));
nMutatedNeuronsSlider.setValue((int) (options.get("nMutatedNeurons").intValue() * 100));
nMutatedConnectionsSlider.setValue((int) (options.get("nMutatedConnections").intValue() * 100));
mutationFactorSlider.setValue((int) (options.get("mutationFactor").intValue() * 100));
updateSettings();
}
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel container; private javax.swing.JPanel container;
private javax.swing.JSlider corpseDecaySlider; private javax.swing.JSlider corpseDecaySlider;
private javax.swing.JList creatureList; private javax.swing.JList creatureList;
private javax.swing.JPanel creaturesPanel;
private javax.swing.JLabel currentCorpseDecay; private javax.swing.JLabel currentCorpseDecay;
private javax.swing.JLabel currentFpsLimit; private javax.swing.JLabel currentFpsLimit;
private javax.swing.JLabel currentHpDecay; private javax.swing.JLabel currentHpDecay;
@ -1073,11 +1185,10 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private javax.swing.JMenu jMenu3; private javax.swing.JMenu jMenu3;
private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton loadBrainBtn; private javax.swing.JButton loadBrainBtn;
private javax.swing.JButton loadSettingsBtn;
private javax.swing.JComboBox logLevelBox; private javax.swing.JComboBox logLevelBox;
private javax.swing.JPanel logPane; private javax.swing.JPanel logPane;
private javax.swing.JTextArea logTextArea; private javax.swing.JTextArea logTextArea;
@ -1093,6 +1204,8 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
private javax.swing.JToggleButton pauseButton; private javax.swing.JToggleButton pauseButton;
private javax.swing.JMenuItem pauseMenuButton; private javax.swing.JMenuItem pauseMenuButton;
private javax.swing.JButton saveBrainBtn; private javax.swing.JButton saveBrainBtn;
private javax.swing.JButton saveSettingsBtn;
private javax.swing.JPanel settingsPanel;
private javax.swing.JSlider sightRangeSlider; private javax.swing.JSlider sightRangeSlider;
private javax.swing.JMenuItem startButton; private javax.swing.JMenuItem startButton;
private javax.swing.JLabel status; private javax.swing.JLabel status;