|
|
@ -21,7 +21,6 @@ import org.encog.neural.networks.training.propagation.resilient.ResilientPropaga |
|
|
|
import robocode.BattleResults; |
|
|
|
import robocode.BattleResults; |
|
|
|
import robocode.control.*; |
|
|
|
import robocode.control.*; |
|
|
|
import robocode.control.events.*; |
|
|
|
import robocode.control.events.*; |
|
|
|
|
|
|
|
|
|
|
|
import neural.Palette; |
|
|
|
import neural.Palette; |
|
|
|
|
|
|
|
|
|
|
|
public class BattlefieldParameterEvaluator { |
|
|
|
public class BattlefieldParameterEvaluator { |
|
|
@ -45,11 +44,15 @@ public class BattlefieldParameterEvaluator { |
|
|
|
final static double NN_TRAINING_ERROR = 0.001; |
|
|
|
final static double NN_TRAINING_ERROR = 0.001; |
|
|
|
// Maximum robot score obtained - used for scaling <0,1>
|
|
|
|
// Maximum robot score obtained - used for scaling <0,1>
|
|
|
|
final static int BATTLE_MAX_SCORE = 250; |
|
|
|
final static int BATTLE_MAX_SCORE = 250; |
|
|
|
|
|
|
|
/* The name of the palette. Must be one of "Spectrum", |
|
|
|
|
|
|
|
* "PaleSpectrum", "Grayscale", "CyclicGrayscale", "CyclicRedCyan", |
|
|
|
|
|
|
|
* "EarthSky", "HotCold", or "Fire". */ |
|
|
|
|
|
|
|
final static String PALETTE = "PaleSpectrum"; |
|
|
|
|
|
|
|
|
|
|
|
static int NdxBattle; |
|
|
|
static int NdxBattle; |
|
|
|
static double[] FinalScore1; |
|
|
|
static double[] FinalScore1; |
|
|
|
static double[] FinalScore2; |
|
|
|
static double[] FinalScore2; |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
double[] BattlefieldSize = new double[NUMSAMPLES]; |
|
|
|
double[] BattlefieldSize = new double[NUMSAMPLES]; |
|
|
|
double[] GunCoolingRate = new double[NUMSAMPLES]; |
|
|
|
double[] GunCoolingRate = new double[NUMSAMPLES]; |
|
|
@ -75,7 +78,7 @@ public class BattlefieldParameterEvaluator { |
|
|
|
RobotSpecification[] competingRobots = engine.getLocalRepository("sample.RamFire,sample.TrackFire"); |
|
|
|
RobotSpecification[] competingRobots = engine.getLocalRepository("sample.RamFire,sample.TrackFire"); |
|
|
|
RobotSetup[] robotSetups = new RobotSetup[2]; |
|
|
|
RobotSetup[] robotSetups = new RobotSetup[2]; |
|
|
|
for (NdxBattle = 0; NdxBattle < NUMSAMPLES; NdxBattle++) { |
|
|
|
for (NdxBattle = 0; NdxBattle < NUMSAMPLES; NdxBattle++) { |
|
|
|
// Choose the battlefield size and gun cooling rate
|
|
|
|
// Choose the battlefield size and gun cooling rate
|
|
|
|
BattlefieldSize[NdxBattle] = rangedRand(rng, MINBATTLEFIELDSIZE, MAXBATTLEFIELDSIZE); |
|
|
|
BattlefieldSize[NdxBattle] = rangedRand(rng, MINBATTLEFIELDSIZE, MAXBATTLEFIELDSIZE); |
|
|
|
GunCoolingRate[NdxBattle] = rangedRand(rng, MINGUNCOOLINGRATE, MAXGUNCOOLINGRATE); |
|
|
|
GunCoolingRate[NdxBattle] = rangedRand(rng, MINGUNCOOLINGRATE, MAXGUNCOOLINGRATE); |
|
|
|
// BattlefieldSize[NdxBattle] = MAXBATTLEFIELDSIZE * (0.1 + 0.9 * rng.nextDouble());
|
|
|
|
// BattlefieldSize[NdxBattle] = MAXBATTLEFIELDSIZE * (0.1 + 0.9 * rng.nextDouble());
|
|
|
@ -99,12 +102,13 @@ public class BattlefieldParameterEvaluator { |
|
|
|
System.out.println(Arrays.toString(GunCoolingRate)); |
|
|
|
System.out.println(Arrays.toString(GunCoolingRate)); |
|
|
|
System.out.println(Arrays.toString(FinalScore1)); |
|
|
|
System.out.println(Arrays.toString(FinalScore1)); |
|
|
|
System.out.println(Arrays.toString(FinalScore2)); |
|
|
|
System.out.println(Arrays.toString(FinalScore2)); |
|
|
|
|
|
|
|
|
|
|
|
// Create the training dataset for the neural network
|
|
|
|
// Create the training dataset for the neural network
|
|
|
|
double[][] RawInputs = new double[NUMSAMPLES][NUM_NN_INPUTS]; |
|
|
|
double[][] RawInputs = new double[NUMSAMPLES][NUM_NN_INPUTS]; |
|
|
|
double[][] RawOutputs = new double[NUMSAMPLES][1]; |
|
|
|
double[][] RawOutputs = new double[NUMSAMPLES][1]; |
|
|
|
for (int NdxSample = 0; NdxSample < NUMSAMPLES; NdxSample++) { |
|
|
|
for (int NdxSample = 0; NdxSample < NUMSAMPLES; NdxSample++) { |
|
|
|
// IMPORTANT: normalize the inputs and the outputs to
|
|
|
|
// IMPORTANT: normalize the inputs and the outputs to
|
|
|
|
// the interval [0,1]
|
|
|
|
// the interval [0,1]
|
|
|
|
RawInputs[NdxSample][0] = BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE; |
|
|
|
RawInputs[NdxSample][0] = BattlefieldSize[NdxSample] / MAXBATTLEFIELDSIZE; |
|
|
|
RawInputs[NdxSample][1] = GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE; |
|
|
|
RawInputs[NdxSample][1] = GunCoolingRate[NdxSample] / MAXGUNCOOLINGRATE; |
|
|
|
RawOutputs[NdxSample][0] = FinalScore1[NdxSample] / BATTLE_MAX_SCORE; |
|
|
|
RawOutputs[NdxSample][0] = FinalScore1[NdxSample] / BATTLE_MAX_SCORE; |
|
|
@ -112,7 +116,7 @@ public class BattlefieldParameterEvaluator { |
|
|
|
|
|
|
|
|
|
|
|
BasicMLDataSet MyDataSet = new BasicMLDataSet(RawInputs, RawOutputs); |
|
|
|
BasicMLDataSet MyDataSet = new BasicMLDataSet(RawInputs, RawOutputs); |
|
|
|
|
|
|
|
|
|
|
|
// Create and train the neural network
|
|
|
|
// Create and train the neural network
|
|
|
|
BasicNetwork network = new BasicNetwork(); |
|
|
|
BasicNetwork network = new BasicNetwork(); |
|
|
|
network.addLayer(new BasicLayer(null, true, NUM_NN_INPUTS)); |
|
|
|
network.addLayer(new BasicLayer(null, true, NUM_NN_INPUTS)); |
|
|
|
network.addLayer(new BasicLayer(new ActivationSigmoid(), true, NUM_NN_HIDDEN_UNITS)); |
|
|
|
network.addLayer(new BasicLayer(new ActivationSigmoid(), true, NUM_NN_HIDDEN_UNITS)); |
|
|
@ -149,7 +153,9 @@ public class BattlefieldParameterEvaluator { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Palette palette = new Palette(); |
|
|
|
// Palette palette = new Palette();
|
|
|
|
|
|
|
|
Palette palette = Palette.makeDefaultPalette(PALETTE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Simulate the neural network with the test samples and fill a matrix
|
|
|
|
// Simulate the neural network with the test samples and fill a matrix
|
|
|
|
for (int NdxBattleSize = 0; NdxBattleSize < NUMBATTLEFIELDSIZES; NdxBattleSize++) { |
|
|
|
for (int NdxBattleSize = 0; NdxBattleSize < NUMBATTLEFIELDSIZES; NdxBattleSize++) { |
|
|
@ -186,7 +192,7 @@ public class BattlefieldParameterEvaluator { |
|
|
|
} |
|
|
|
} |
|
|
|
BufferedImage img = new BufferedImage(NUMCOOLINGRATES, NUMBATTLEFIELDSIZES, BufferedImage.TYPE_INT_RGB); |
|
|
|
BufferedImage img = new BufferedImage(NUMCOOLINGRATES, NUMBATTLEFIELDSIZES, BufferedImage.TYPE_INT_RGB); |
|
|
|
img.setRGB(0, 0, NUMCOOLINGRATES, NUMBATTLEFIELDSIZES, OutputRGBint, 0, NUMCOOLINGRATES); |
|
|
|
img.setRGB(0, 0, NUMCOOLINGRATES, NUMBATTLEFIELDSIZES, OutputRGBint, 0, NUMCOOLINGRATES); |
|
|
|
File f = new File("hello.png"); |
|
|
|
File f = new File("hello_" + PALETTE + ".png"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
ImageIO.write(img, "png", f); |
|
|
|
ImageIO.write(img, "png", f); |
|
|
|
} |
|
|
|
} |
|
|
@ -217,7 +223,7 @@ public class BattlefieldParameterEvaluator { |
|
|
|
static class BattleObserver extends BattleAdaptor { |
|
|
|
static class BattleObserver extends BattleAdaptor { |
|
|
|
// Called when the battle is completed successfully with battle results
|
|
|
|
// Called when the battle is completed successfully with battle results
|
|
|
|
public void onBattleCompleted(BattleCompletedEvent e) { |
|
|
|
public void onBattleCompleted(BattleCompletedEvent e) { |
|
|
|
System.out.println("‐‐ Battle has completed ‐‐"); |
|
|
|
System.out.println("Battle has completed."); |
|
|
|
// Get the indexed battle results
|
|
|
|
// Get the indexed battle results
|
|
|
|
BattleResults[] results = e.getIndexedResults(); |
|
|
|
BattleResults[] results = e.getIndexedResults(); |
|
|
|
// Print out the indexed results with the robot names
|
|
|
|
// Print out the indexed results with the robot names
|
|
|
|