Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9567 was 9565, checked in by melkaref, 12 years ago

Robocode Plugin code without Mutation Operators

File size: 3.3 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        public new Solution Content
24        {
25            get { return (Solution)base.Content; }
26            set { base.Content = value; }
27        }
28
29        public SolutionCodeView() : base()
30        {
31            InitializeComponent();
32            this.programCode.Text = "";
33        }
34
35        protected override void OnContentChanged()
36        {
37            base.OnContentChanged();
38            if (Content == null)
39            {
40                this.programCode.Text = "";
41            }
42            else
43            {
44                string code = Interpreter.InterpretProgramTree(Content.Tree.Root);
45                code = code.Replace("class output extends", "class BestSolution extends");
46                this.programCode.Text = code;
47                File.AppendAllText("F:/robocode/robots/Evaluation/PreviousBestSolution.java", "\r\n/**********************************************/\r\n" + code);
48                File.WriteAllText("F:/robocode/robots/Evaluation/BestSolution.java", code, System.Text.Encoding.Default);
49            }
50        }
51
52        private void btnRunInRobocode_Click(object sender, EventArgs e)
53        {
54            ProcessStartInfo javaCompileInfo = new ProcessStartInfo();
55            javaCompileInfo.FileName = "cmd.exe";
56            javaCompileInfo.Arguments = "/C javac -cp F:\\robocode\\libs\\robocode.jar F:\\robocode\\robots\\Evaluation\\BestSolution.java";
57            javaCompileInfo.RedirectStandardOutput = true;
58            javaCompileInfo.RedirectStandardError = true;
59            javaCompileInfo.UseShellExecute = false;
60            javaCompileInfo.CreateNoWindow = true;
61
62            Process javaCompile = new Process();
63            javaCompile.StartInfo = javaCompileInfo;
64            javaCompile.Start();
65            javaCompile.WaitForExit();
66
67            ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo();
68            evaluateCodeInfo.FileName = "cmd.exe";
69            //javaCompileInfo.Arguments = "/C javac -cp C:\\robocode\\libs\\robocode.jar \"" + path + "\\Spaced Up\\output.java\"";
70            evaluateCodeInfo.Arguments = "/C java -classpath F:\\robocode\\libs;F:\\robocode\\libs\\robocode.core-1.8.1.0.jar;F:\\robocode\\libs\\robocode.jar;F:\\robocode\\libs\\picocontainer-2.14.2.jar BattleRunner Evaluation.BestSolution*";
71            //Console.WriteLine(javaCompileInfo.Arguments);
72            evaluateCodeInfo.RedirectStandardOutput = true;
73            evaluateCodeInfo.RedirectStandardError = true;
74            evaluateCodeInfo.UseShellExecute = false;
75
76            Process evaluateCode = new Process();
77            evaluateCode.StartInfo = evaluateCodeInfo;
78            evaluateCode.Start();
79            evaluateCode.WaitForExit();
80        }
81    }
82}
Note: See TracBrowser for help on using the repository browser.