[9565] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Threading.Tasks;
|
---|
| 9 | using System.Windows.Forms;
|
---|
| 10 | using HeuristicLab.Core.Views;
|
---|
| 11 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
| 12 | using HeuristicLab.MainForm;
|
---|
| 13 | using System.Diagnostics;
|
---|
| 14 | using System.IO;
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | namespace HeuristicLab.Problems.Robocode
|
---|
| 18 | {
|
---|
| 19 | [View("Robocode Tank Code View")]
|
---|
| 20 | [Content(typeof(Solution), IsDefaultView = true)]
|
---|
| 21 | public partial class SolutionCodeView : NamedItemView
|
---|
| 22 | {
|
---|
[9570] | 23 | private string Path { get; set; }
|
---|
| 24 |
|
---|
[9565] | 25 | public new Solution Content
|
---|
| 26 | {
|
---|
| 27 | get { return (Solution)base.Content; }
|
---|
| 28 | set { base.Content = value; }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public SolutionCodeView() : base()
|
---|
| 32 | {
|
---|
| 33 | InitializeComponent();
|
---|
[9570] | 34 | this.Path = "F:/robocode/";
|
---|
[9565] | 35 | this.programCode.Text = "";
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | protected override void OnContentChanged()
|
---|
| 39 | {
|
---|
| 40 | base.OnContentChanged();
|
---|
| 41 | if (Content == null)
|
---|
| 42 | {
|
---|
| 43 | this.programCode.Text = "";
|
---|
| 44 | }
|
---|
| 45 | else
|
---|
| 46 | {
|
---|
[9570] | 47 | this.Path = Content.Path;
|
---|
[9565] | 48 | string code = Interpreter.InterpretProgramTree(Content.Tree.Root);
|
---|
| 49 | code = code.Replace("class output extends", "class BestSolution extends");
|
---|
| 50 | this.programCode.Text = code;
|
---|
[9570] | 51 | File.AppendAllText(Path + "/robots/Evaluation/PreviousBestSolution.java", "\r\n/**********************************************/\r\n" + code);
|
---|
| 52 | File.WriteAllText(Path + "/robots/Evaluation/BestSolution.java", code, System.Text.Encoding.Default);
|
---|
[9565] | 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | private void btnRunInRobocode_Click(object sender, EventArgs e)
|
---|
| 57 | {
|
---|
[9570] | 58 | string formattedPath = Path.Replace("/", "\\");
|
---|
[9565] | 59 | ProcessStartInfo javaCompileInfo = new ProcessStartInfo();
|
---|
| 60 | javaCompileInfo.FileName = "cmd.exe";
|
---|
[9570] | 61 | javaCompileInfo.Arguments = "/C javac -cp " + formattedPath + "\\libs\\robocode.jar " + formattedPath + "\\robots\\Evaluation\\BestSolution.java";
|
---|
[9565] | 62 | javaCompileInfo.RedirectStandardOutput = true;
|
---|
| 63 | javaCompileInfo.RedirectStandardError = true;
|
---|
| 64 | javaCompileInfo.UseShellExecute = false;
|
---|
| 65 | javaCompileInfo.CreateNoWindow = true;
|
---|
| 66 |
|
---|
| 67 | Process javaCompile = new Process();
|
---|
| 68 | javaCompile.StartInfo = javaCompileInfo;
|
---|
| 69 | javaCompile.Start();
|
---|
| 70 | javaCompile.WaitForExit();
|
---|
| 71 |
|
---|
| 72 | ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo();
|
---|
| 73 | evaluateCodeInfo.FileName = "cmd.exe";
|
---|
| 74 | //javaCompileInfo.Arguments = "/C javac -cp C:\\robocode\\libs\\robocode.jar \"" + path + "\\Spaced Up\\output.java\"";
|
---|
[9570] | 75 | evaluateCodeInfo.Arguments = "/C java -classpath " + formattedPath + "\\libs;" + formattedPath + "\\libs\\robocode.core-1.8.1.0.jar;" + formattedPath + "\\libs\\robocode.jar;" + formattedPath + "\\libs\\picocontainer-2.14.2.jar BattleRunner Evaluation.BestSolution*";
|
---|
[9565] | 76 | //Console.WriteLine(javaCompileInfo.Arguments);
|
---|
| 77 | evaluateCodeInfo.RedirectStandardOutput = true;
|
---|
| 78 | evaluateCodeInfo.RedirectStandardError = true;
|
---|
| 79 | evaluateCodeInfo.UseShellExecute = false;
|
---|
| 80 |
|
---|
| 81 | Process evaluateCode = new Process();
|
---|
| 82 | evaluateCode.StartInfo = evaluateCodeInfo;
|
---|
| 83 | evaluateCode.Start();
|
---|
| 84 | evaluateCode.WaitForExit();
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|