#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Diagnostics; using System.IO; using System.Windows.Forms; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; 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(); } } }