diff --git a/.classpath b/.classpath
index b5440fb..b492a72 100644
--- a/.classpath
+++ b/.classpath
@@ -7,6 +7,6 @@
-
+
diff --git a/src/neural/BattlefieldParameterEvaluator.java b/src/neural/BattlefieldParameterEvaluator.java
index 8eaeea0..e4bd11e 100644
--- a/src/neural/BattlefieldParameterEvaluator.java
+++ b/src/neural/BattlefieldParameterEvaluator.java
@@ -6,13 +6,16 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
+
import javax.imageio.ImageIO;
+
import org.encog.engine.network.activation.ActivationSigmoid;
import org.encog.ml.data.basic.BasicMLData;
import org.encog.neural.data.basic.BasicNeuralDataSet;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.layers.BasicLayer;
import org.encog.neural.networks.training.propagation.resilient.ResilientPropagation;
+
import robocode.BattleResults;
import robocode.control.*;
import robocode.control.events.*;
@@ -36,7 +39,7 @@ public class BattlefieldParameterEvaluator {
static int NdxBattle;
static double[] FinalScore1;
static double[] FinalScore2;
-
+
public static void main(String[] args) {
double[] BattlefieldSize = new double[NUMSAMPLES];
double[] GunCoolingRate = new double[NUMSAMPLES];
@@ -63,8 +66,10 @@ public class BattlefieldParameterEvaluator {
RobotSetup[] robotSetups = new RobotSetup[2];
for (NdxBattle = 0; NdxBattle < NUMSAMPLES; NdxBattle++) {
// Choose the battlefield size and gun cooling rate
- BattlefieldSize[NdxBattle] = MAXBATTLEFIELDSIZE * (0.1 + 0.9 * rng.nextDouble());
- GunCoolingRate[NdxBattle] = MAXGUNCOOLINGRATE * (0.1 + 0.9 * rng.nextDouble());
+// BattlefieldSize[NdxBattle] = MAXBATTLEFIELDSIZE * (0.1 + 0.9 * rng.nextDouble());
+ BattlefieldSize[NdxBattle] = rangedRand(rng, MINBATTLEFIELDSIZE, MAXBATTLEFIELDSIZE);
+// GunCoolingRate[NdxBattle] = MAXGUNCOOLINGRATE * (0.1 + 0.9 * rng.nextDouble());
+ GunCoolingRate[NdxBattle] = rangedRand(rng, MINGUNCOOLINGRATE, MAXGUNCOOLINGRATE);
// Create the battlefield
BattlefieldSpecification battlefield = new BattlefieldSpecification((int) BattlefieldSize[NdxBattle],
(int) BattlefieldSize[NdxBattle]);
@@ -79,7 +84,7 @@ public class BattlefieldParameterEvaluator {
}
// Cleanup our RobocodeEngine
engine.close();
- System.out.println("END");
+ System.out.println("Fight ended:");
System.out.println(Arrays.toString(BattlefieldSize));
System.out.println(Arrays.toString(GunCoolingRate));
System.out.println(Arrays.toString(FinalScore1));
@@ -116,7 +121,7 @@ public class BattlefieldParameterEvaluator {
// Simulate the neural network with the test samples and fill a matrix
for (int NdxBattleSize = 0; NdxBattleSize < NUMBATTLEFIELDSIZES; NdxBattleSize++) {
for (int NdxCooling = 0; NdxCooling < NUMCOOLINGRATES; NdxCooling++) {
- // INSERT SOMETHING HERE
+ // TODO INSERT SOMETHING HERE
double MyResult = 0.0; // MyTestData[NdxCooling+NdxBattleSize*NUMCOOLINGRATES];
MyValue = ClipColor(MyResult);
MyColor = new Color((float) MyValue, (float) MyValue, (float) MyValue);
@@ -184,7 +189,7 @@ public class BattlefieldParameterEvaluator {
// Called when the game sends out an information message during the battle
public void onBattleMessage(BattleMessageEvent e) {
- // System.out.println("Msg> " + e.getMessage());
+// System.out.println("Msg> " + e.getMessage());
}
// Called when the game sends out an error message during the battle
@@ -192,4 +197,33 @@ public class BattlefieldParameterEvaluator {
System.out.println("Err> " + e.getError());
}
}
+
+
+
+ /**
+ * Returns a pseudo-random number between min and max, inclusive. The difference between min and max can be at most
+ *
+ * @param min
+ * Minimum value
+ * @param max
+ * Maximum value. Must be greater than min.
+ * @return Double between min and max, inclusive.
+ * @see java.util.Random#nextDouble(int)
+ */
+ private static double rangedRand(Random rng, double min, double max) {
+
+ // Make sure the randomizer was initialised
+ if (rng == null)
+ throw new RuntimeException("PRNG not initialised prior to call");
+
+ // Check for the limit
+ if (Double.valueOf(max - min).isInfinite())
+ throw new RuntimeException("Value od max - min is infinite. Change the range.");
+
+ // nextInt is normally exclusive of the top value, so add 1 to make it inclusive
+ double randomNum = min + (max - min) * rng.nextDouble();
+// int randomNum = rng.nextDouble((max - min) + 1) + min;
+
+ return randomNum;
+ }
}