Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode/HeuristicLab.Problems.Robocode/SolutionCodeView.cs @ 9598

Last change on this file since 9598 was 9570, checked in by melkaref, 12 years ago

Fixed SolutionCodeView to use the specified Path variable

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using HeuristicLab.Core.Views;
11using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
12using HeuristicLab.MainForm;
13using System.Diagnostics;
14using System.IO;
15
16
17namespace HeuristicLab.Problems.Robocode
18{
19    [View("Robocode Tank Code View")]
20    [Content(typeof(Solution), IsDefaultView = true)]
21    public partial class SolutionCodeView : NamedItemView
22    {
23        private string Path { get; set; }
24
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();
34            this.Path = "F:/robocode/";
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            {
47                this.Path = Content.Path;
48                string code = Interpreter.InterpretProgramTree(Content.Tree.Root);
49                code = code.Replace("class output extends", "class BestSolution extends");
50                this.programCode.Text = code;
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);
53            }
54        }
55
56        private void btnRunInRobocode_Click(object sender, EventArgs e)
57        {
58            string formattedPath = Path.Replace("/", "\\");
59            ProcessStartInfo javaCompileInfo = new ProcessStartInfo();
60            javaCompileInfo.FileName = "cmd.exe";
61            javaCompileInfo.Arguments = "/C javac -cp " + formattedPath + "\\libs\\robocode.jar " + formattedPath + "\\robots\\Evaluation\\BestSolution.java";
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\"";
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*";
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}
Note: See TracBrowser for help on using the repository browser.