1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Threading.Tasks;
|
---|
9 | using System.Windows.Forms;
|
---|
10 | using HeuristicLab.Core.Views;
|
---|
11 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
12 | using HeuristicLab.MainForm;
|
---|
13 | using System.Diagnostics;
|
---|
14 | using System.IO;
|
---|
15 |
|
---|
16 |
|
---|
17 | namespace 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 | }
|
---|