[9790] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Diagnostics;
|
---|
| 24 | using System.IO;
|
---|
[9779] | 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 |
|
---|
[9790] | 30 | namespace HeuristicLab.Problems.Robocode {
|
---|
| 31 | [View("Robocode Tank Code View")]
|
---|
| 32 | [Content(typeof(Solution), IsDefaultView = true)]
|
---|
| 33 | public partial class SolutionCodeView : NamedItemView {
|
---|
| 34 | private string Path { get; set; }
|
---|
[9779] | 35 |
|
---|
[9790] | 36 | public new Solution Content {
|
---|
| 37 | get { return (Solution)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
[9779] | 40 |
|
---|
[9790] | 41 | public SolutionCodeView()
|
---|
| 42 | : base() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | this.Path = "F:/robocode/";
|
---|
| 45 | this.programCode.Text = "";
|
---|
| 46 | }
|
---|
[9779] | 47 |
|
---|
[9790] | 48 | protected override void OnContentChanged() {
|
---|
| 49 | base.OnContentChanged();
|
---|
| 50 | if (Content == null) {
|
---|
| 51 | this.programCode.Text = "";
|
---|
| 52 | } else {
|
---|
| 53 | this.Path = Content.Path;
|
---|
| 54 | string code = Interpreter.InterpretProgramTree(Content.Tree.Root);
|
---|
| 55 | code = code.Replace("class output extends", "class BestSolution extends");
|
---|
| 56 | this.programCode.Text = code;
|
---|
| 57 | File.AppendAllText(Path + "/robots/Evaluation/PreviousBestSolution.java", "\r\n/**********************************************/\r\n" + code);
|
---|
| 58 | File.WriteAllText(Path + "/robots/Evaluation/BestSolution.java", code, System.Text.Encoding.Default);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
[9779] | 61 |
|
---|
[9790] | 62 | private void btnRunInRobocode_Click(object sender, EventArgs e) {
|
---|
| 63 | string formattedPath = Path.Replace("/", "\\");
|
---|
| 64 | ProcessStartInfo javaCompileInfo = new ProcessStartInfo();
|
---|
| 65 | javaCompileInfo.FileName = "cmd.exe";
|
---|
| 66 | javaCompileInfo.Arguments = "/C javac -cp " + formattedPath + "\\libs\\robocode.jar " + formattedPath + "\\robots\\Evaluation\\BestSolution.java";
|
---|
| 67 | javaCompileInfo.RedirectStandardOutput = true;
|
---|
| 68 | javaCompileInfo.RedirectStandardError = true;
|
---|
| 69 | javaCompileInfo.UseShellExecute = false;
|
---|
| 70 | javaCompileInfo.CreateNoWindow = true;
|
---|
[9779] | 71 |
|
---|
[9790] | 72 | Process javaCompile = new Process();
|
---|
| 73 | javaCompile.StartInfo = javaCompileInfo;
|
---|
| 74 | javaCompile.Start();
|
---|
| 75 | javaCompile.WaitForExit();
|
---|
[9779] | 76 |
|
---|
[9790] | 77 | ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo();
|
---|
| 78 | evaluateCodeInfo.FileName = "cmd.exe";
|
---|
| 79 | //javaCompileInfo.Arguments = "/C javac -cp C:\\robocode\\libs\\robocode.jar \"" + path + "\\Spaced Up\\output.java\"";
|
---|
| 80 | 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*";
|
---|
| 81 | //Console.WriteLine(javaCompileInfo.Arguments);
|
---|
| 82 | evaluateCodeInfo.RedirectStandardOutput = true;
|
---|
| 83 | evaluateCodeInfo.RedirectStandardError = true;
|
---|
| 84 | evaluateCodeInfo.UseShellExecute = false;
|
---|
[9779] | 85 |
|
---|
[9790] | 86 | Process evaluateCode = new Process();
|
---|
| 87 | evaluateCode.StartInfo = evaluateCodeInfo;
|
---|
| 88 | evaluateCode.Start();
|
---|
| 89 | evaluateCode.WaitForExit();
|
---|
[9779] | 90 | }
|
---|
[9790] | 91 | }
|
---|
[9779] | 92 | }
|
---|