using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using HeuristicLab.Core.Views; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; using HeuristicLab.MainForm; using System.Diagnostics; using System.IO; namespace HeuristicLab.Problems.Robocode { [View("Robocode Tank Code View")] [Content(typeof(Solution), IsDefaultView = true)] public partial class SolutionCodeView : NamedItemView { private string Path { get; set; } public new Solution Content { get { return (Solution)base.Content; } set { base.Content = value; } } public SolutionCodeView() : base() { InitializeComponent(); this.Path = "F:/robocode/"; this.programCode.Text = ""; } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { this.programCode.Text = ""; } else { this.Path = Content.Path; string code = Interpreter.InterpretProgramTree(Content.Tree.Root); code = code.Replace("class output extends", "class BestSolution extends"); this.programCode.Text = code; File.AppendAllText(Path + "/robots/Evaluation/PreviousBestSolution.java", "\r\n/**********************************************/\r\n" + code); File.WriteAllText(Path + "/robots/Evaluation/BestSolution.java", code, System.Text.Encoding.Default); } } private void btnRunInRobocode_Click(object sender, EventArgs e) { string formattedPath = Path.Replace("/", "\\"); ProcessStartInfo javaCompileInfo = new ProcessStartInfo(); javaCompileInfo.FileName = "cmd.exe"; javaCompileInfo.Arguments = "/C javac -cp " + formattedPath + "\\libs\\robocode.jar " + formattedPath + "\\robots\\Evaluation\\BestSolution.java"; javaCompileInfo.RedirectStandardOutput = true; javaCompileInfo.RedirectStandardError = true; javaCompileInfo.UseShellExecute = false; javaCompileInfo.CreateNoWindow = true; Process javaCompile = new Process(); javaCompile.StartInfo = javaCompileInfo; javaCompile.Start(); javaCompile.WaitForExit(); ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo(); evaluateCodeInfo.FileName = "cmd.exe"; //javaCompileInfo.Arguments = "/C javac -cp C:\\robocode\\libs\\robocode.jar \"" + path + "\\Spaced Up\\output.java\""; 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*"; //Console.WriteLine(javaCompileInfo.Arguments); evaluateCodeInfo.RedirectStandardOutput = true; evaluateCodeInfo.RedirectStandardError = true; evaluateCodeInfo.UseShellExecute = false; Process evaluateCode = new Process(); evaluateCode.StartInfo = evaluateCodeInfo; evaluateCode.Start(); evaluateCode.WaitForExit(); } } }