package neural; import java.util.Arrays; import java.awt.Color; 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.*; public class BattlefieldParameterEvaluator { // Minimum allowable battlefield size is 400 final static int MAXBATTLEFIELDSIZE = 4000; // Minimum allowable gun cooling rate is 0.1 final static double MAXGUNCOOLINGRATE = 10; final static int NUMBATTLEFIELDSIZES = 601; final static int NUMCOOLINGRATES = 501; final static int NUMSAMPLES = 1000; // Number of inputs for the multilayer perceptron (size of the input vectors) final static int NUM_NN_INPUTS = 2; // Number of hidden neurons of the neural network final static int NUM_NN_HIDDEN_UNITS = 50; // Number of epochs for training final static int NUM_TRAINING_EPOCHS = 100000; 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]; FinalScore1=new double[NUMSAMPLES]; FinalScore2=new double[NUMSAMPLES]; Random rng=new Random(15L); // Disable log messages from Robocode RobocodeEngine.setLogMessagesEnabled(false); // Create the RobocodeEngine // Run from C:/Robocode RobocodeEngine engine = new RobocodeEngine(new java.io.File("C:/Robocode")); // Add our own battle listener to the RobocodeEngine engine.addBattleListener(new BattleObserver()); // Show the Robocode battle view engine.setVisible(false); // Setup the battle specification // Setup battle parameters int numberOfRounds = 1; long inactivityTime = 100; int sentryBorderSize = 50; boolean hideEnemyNames = false; // Get the robots and set up their initial states RobotSpecification[] competingRobots = engine.getLocalRepository("sample.RamFire,sample.TrackFire"); RobotSetup[] robotSetups = new RobotSetup[2]; for(NdxBattle=0;NdxBattle=0) && (MyPixelIndex 1.0) { Value = 1.0; } return Value; } // // Our private battle listener for handling the battle event we are interested in. // static class BattleObserver extends BattleAdaptor { // Called when the battle is completed successfully with battle results public void onBattleCompleted(BattleCompletedEvent e) { System.out.println("‐‐ Battle has completed ‐‐"); // Get the indexed battle results BattleResults[] results = e.getIndexedResults(); // Print out the indexed results with the robot names System.out.println("Battle results:"); for (BattleResults result : results) { System.out.println(" " + result.getTeamLeaderName() + ": " + result.getScore()); } // Store the scores of the robots BattlefieldParameterEvaluator.FinalScore1[NdxBattle] = results[0].getScore(); BattlefieldParameterEvaluator.FinalScore2[NdxBattle] = results[1].getScore(); } // Called when the game sends out an information message during the battle public void onBattleMessage(BattleMessageEvent e) { // System.out.println("Msg> " + e.getMessage()); } // Called when the game sends out an error message during the battle public void onBattleError(BattleErrorEvent e) { System.out.println("Err> " + e.getError()); } } }