Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/SolutionCodeView.cs @ 9844

Last change on this file since 9844 was 9790, checked in by ascheibe, 11 years ago

#2069

  • added license headers
  • corrected version information
  • fixed formatting
File size: 3.8 KB
Line 
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
22using System;
23using System.Diagnostics;
24using System.IO;
25using System.Windows.Forms;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29
30namespace 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; }
35
36    public new Solution Content {
37      get { return (Solution)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public SolutionCodeView()
42      : base() {
43      InitializeComponent();
44      this.Path = "F:/robocode/";
45      this.programCode.Text = "";
46    }
47
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    }
61
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;
71
72      Process javaCompile = new Process();
73      javaCompile.StartInfo = javaCompileInfo;
74      javaCompile.Start();
75      javaCompile.WaitForExit();
76
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;
85
86      Process evaluateCode = new Process();
87      evaluateCode.StartInfo = evaluateCodeInfo;
88      evaluateCode.Start();
89      evaluateCode.WaitForExit();
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.