Changeset 9889
- Timestamp:
- 08/21/13 14:38:09 (11 years ago)
- Location:
- branches/Robocode.TrunkInt
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/CodeNodeView.Designer.cs
r9781 r9889 29 29 private void InitializeComponent() 30 30 { 31 this.prefixCode = new System.Windows.Forms.TextBox(); 32 this.prefixLabel = new System.Windows.Forms.Label(); 33 this.suffixLabel = new System.Windows.Forms.Label(); 34 this.suffixCode = new System.Windows.Forms.TextBox(); 35 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 36 this.SuspendLayout(); 37 // 38 // nameTextBox 39 // 40 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 41 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 42 this.nameTextBox.Visible = false; 43 // 44 // nameLabel 45 // 46 this.nameLabel.Visible = false; 47 // 48 // infoLabel 49 // 50 this.infoLabel.Visible = false; 51 // 52 // prefixCode 53 // 54 this.prefixCode.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 55 | System.Windows.Forms.AnchorStyles.Right))); 56 this.prefixCode.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 57 this.prefixCode.Location = new System.Drawing.Point(6, 19); 58 this.prefixCode.Multiline = true; 59 this.prefixCode.Name = "prefixCode"; 60 this.prefixCode.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 61 this.prefixCode.Size = new System.Drawing.Size(333, 93); 62 this.prefixCode.TabIndex = 3; 63 this.prefixCode.Validated += new System.EventHandler(this.prefixCode_Validated); 64 // 65 // prefixLabel 66 // 67 this.prefixLabel.AutoSize = true; 68 this.prefixLabel.Location = new System.Drawing.Point(3, 3); 69 this.prefixLabel.Name = "prefixLabel"; 70 this.prefixLabel.Size = new System.Drawing.Size(33, 13); 71 this.prefixLabel.TabIndex = 4; 72 this.prefixLabel.Text = "Prefix"; 73 // 74 // suffixLabel 75 // 76 this.suffixLabel.AutoSize = true; 77 this.suffixLabel.Location = new System.Drawing.Point(6, 115); 78 this.suffixLabel.Name = "suffixLabel"; 79 this.suffixLabel.Size = new System.Drawing.Size(33, 13); 80 this.suffixLabel.TabIndex = 5; 81 this.suffixLabel.Text = "Suffix"; 82 // 83 // suffixCode 84 // 85 this.suffixCode.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 86 | System.Windows.Forms.AnchorStyles.Right))); 87 this.suffixCode.Location = new System.Drawing.Point(6, 131); 88 this.suffixCode.Multiline = true; 89 this.suffixCode.Name = "suffixCode"; 90 this.suffixCode.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal; 91 this.suffixCode.Size = new System.Drawing.Size(333, 87); 92 this.suffixCode.TabIndex = 6; 93 this.suffixCode.Validated += new System.EventHandler(this.suffixCode_Validated); 94 // 95 // CodeNodeView 96 // 97 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 98 this.Controls.Add(this.suffixCode); 99 this.Controls.Add(this.suffixLabel); 100 this.Controls.Add(this.prefixLabel); 101 this.Controls.Add(this.prefixCode); 102 this.Name = "CodeNodeView"; 103 this.Size = new System.Drawing.Size(351, 238); 104 this.Controls.SetChildIndex(this.nameLabel, 0); 105 this.Controls.SetChildIndex(this.nameTextBox, 0); 106 this.Controls.SetChildIndex(this.infoLabel, 0); 107 this.Controls.SetChildIndex(this.prefixCode, 0); 108 this.Controls.SetChildIndex(this.prefixLabel, 0); 109 this.Controls.SetChildIndex(this.suffixLabel, 0); 110 this.Controls.SetChildIndex(this.suffixCode, 0); 111 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 112 this.ResumeLayout(false); 113 this.PerformLayout(); 31 this.prefixCode = new System.Windows.Forms.TextBox(); 32 this.prefixLabel = new System.Windows.Forms.Label(); 33 this.suffixLabel = new System.Windows.Forms.Label(); 34 this.suffixCode = new System.Windows.Forms.TextBox(); 35 this.splitContainer = new System.Windows.Forms.SplitContainer(); 36 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 37 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 38 this.splitContainer.Panel1.SuspendLayout(); 39 this.splitContainer.Panel2.SuspendLayout(); 40 this.splitContainer.SuspendLayout(); 41 this.SuspendLayout(); 42 // 43 // nameTextBox 44 // 45 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 46 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 47 this.nameTextBox.Size = new System.Drawing.Size(508, 20); 48 this.nameTextBox.Visible = false; 49 // 50 // nameLabel 51 // 52 this.nameLabel.Visible = false; 53 // 54 // infoLabel 55 // 56 this.infoLabel.Location = new System.Drawing.Point(572, 3); 57 this.infoLabel.Visible = false; 58 // 59 // prefixCode 60 // 61 this.prefixCode.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 62 | System.Windows.Forms.AnchorStyles.Left) 63 | System.Windows.Forms.AnchorStyles.Right))); 64 this.prefixCode.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 65 this.prefixCode.Location = new System.Drawing.Point(6, 16); 66 this.prefixCode.Multiline = true; 67 this.prefixCode.Name = "prefixCode"; 68 this.prefixCode.ScrollBars = System.Windows.Forms.ScrollBars.Both; 69 this.prefixCode.Size = new System.Drawing.Size(573, 100); 70 this.prefixCode.TabIndex = 3; 71 this.prefixCode.Validated += new System.EventHandler(this.prefixCode_Validated); 72 // 73 // prefixLabel 74 // 75 this.prefixLabel.AutoSize = true; 76 this.prefixLabel.Location = new System.Drawing.Point(3, 0); 77 this.prefixLabel.Name = "prefixLabel"; 78 this.prefixLabel.Size = new System.Drawing.Size(33, 13); 79 this.prefixLabel.TabIndex = 4; 80 this.prefixLabel.Text = "Prefix"; 81 // 82 // suffixLabel 83 // 84 this.suffixLabel.AutoSize = true; 85 this.suffixLabel.Location = new System.Drawing.Point(3, 0); 86 this.suffixLabel.Name = "suffixLabel"; 87 this.suffixLabel.Size = new System.Drawing.Size(33, 13); 88 this.suffixLabel.TabIndex = 5; 89 this.suffixLabel.Text = "Suffix"; 90 // 91 // suffixCode 92 // 93 this.suffixCode.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 94 | System.Windows.Forms.AnchorStyles.Left) 95 | System.Windows.Forms.AnchorStyles.Right))); 96 this.suffixCode.Location = new System.Drawing.Point(6, 16); 97 this.suffixCode.Multiline = true; 98 this.suffixCode.Name = "suffixCode"; 99 this.suffixCode.ScrollBars = System.Windows.Forms.ScrollBars.Both; 100 this.suffixCode.Size = new System.Drawing.Size(573, 96); 101 this.suffixCode.TabIndex = 6; 102 this.suffixCode.Validated += new System.EventHandler(this.suffixCode_Validated); 103 // 104 // splitContainer 105 // 106 this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 107 | System.Windows.Forms.AnchorStyles.Left) 108 | System.Windows.Forms.AnchorStyles.Right))); 109 this.splitContainer.Location = new System.Drawing.Point(6, 26); 110 this.splitContainer.Name = "splitContainer"; 111 this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal; 112 // 113 // splitContainer.Panel1 114 // 115 this.splitContainer.Panel1.Controls.Add(this.prefixLabel); 116 this.splitContainer.Panel1.Controls.Add(this.prefixCode); 117 // 118 // splitContainer.Panel2 119 // 120 this.splitContainer.Panel2.Controls.Add(this.suffixLabel); 121 this.splitContainer.Panel2.Controls.Add(this.suffixCode); 122 this.splitContainer.Size = new System.Drawing.Size(582, 238); 123 this.splitContainer.SplitterDistance = 119; 124 this.splitContainer.TabIndex = 7; 125 // 126 // CodeNodeView 127 // 128 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 129 this.Controls.Add(this.splitContainer); 130 this.Name = "CodeNodeView"; 131 this.Size = new System.Drawing.Size(591, 267); 132 this.Controls.SetChildIndex(this.nameLabel, 0); 133 this.Controls.SetChildIndex(this.nameTextBox, 0); 134 this.Controls.SetChildIndex(this.infoLabel, 0); 135 this.Controls.SetChildIndex(this.splitContainer, 0); 136 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 137 this.splitContainer.Panel1.ResumeLayout(false); 138 this.splitContainer.Panel1.PerformLayout(); 139 this.splitContainer.Panel2.ResumeLayout(false); 140 this.splitContainer.Panel2.PerformLayout(); 141 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 142 this.splitContainer.ResumeLayout(false); 143 this.ResumeLayout(false); 144 this.PerformLayout(); 114 145 115 146 } … … 121 152 private System.Windows.Forms.Label suffixLabel; 122 153 private System.Windows.Forms.TextBox suffixCode; 154 private System.Windows.Forms.SplitContainer splitContainer; 123 155 } 124 156 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/CodeNodeView.cs
r9790 r9889 21 21 22 22 using System; 23 using System.Windows.Forms;24 23 using HeuristicLab.Core.Views; 25 24 using HeuristicLab.MainForm; 26 27 25 28 26 namespace HeuristicLab.Problems.Robocode { … … 43 41 base.OnContentChanged(); 44 42 if (Content == null) { 45 this.prefixCode.Text = "";46 this.suffixCode.Text = "";43 this.prefixCode.Text = string.Empty; 44 this.suffixCode.Text = string.Empty; 47 45 } else { 48 46 this.prefixCode.Text = Content.Prefix; -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/CodeNodeView.resx
r9781 r9889 119 119 </resheader> 120 120 <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 121 <value>107, 17</value> 122 </metadata> 123 <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 124 <value>107, 17</value> 121 <value>17, 17</value> 125 122 </metadata> 126 123 <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 127 <value>1 7, 17</value>124 <value>140, 17</value> 128 125 </metadata> 129 126 </root> -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/HeuristicLab.Problems.Robocode.Views-3.3.csproj
r9787 r9889 131 131 <DependentUpon>SolutionCodeView.cs</DependentUpon> 132 132 </EmbeddedResource> 133 <EmbeddedResource Include="SolutionProgramView.resx"> 134 <DependentUpon>SolutionProgramView.cs</DependentUpon> 135 </EmbeddedResource> 133 136 </ItemGroup> 134 137 <ItemGroup> -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/SolutionCodeView.cs
r9880 r9889 21 21 22 22 using System; 23 using System.Diagnostics;24 using System.IO;25 using System.Windows.Forms;26 23 using HeuristicLab.Core.Views; 27 24 using HeuristicLab.MainForm; 28 29 25 30 26 namespace HeuristicLab.Problems.Robocode { … … 32 28 [Content(typeof(Solution), IsDefaultView = true)] 33 29 public partial class SolutionCodeView : NamedItemView { 34 private string Path { get; set; }35 36 30 public new Solution Content { 37 31 get { return (Solution)base.Content; } … … 42 36 : base() { 43 37 InitializeComponent(); 44 this.Path = "c:/robocode/";45 this.programCode.Text = "";46 38 } 47 39 … … 49 41 base.OnContentChanged(); 50 42 if (Content == null) { 51 this.programCode.Text = "";43 this.programCode.Text = string.Empty; 52 44 } 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); 45 this.programCode.Text = Interpreter.InterpretProgramTree(Content.Tree.Root, "BestSolution"); 59 46 } 60 47 } 61 48 62 49 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(); 50 Interpreter.EvaluateTankProgram(Content.Tree, Content.Path, "BestSolution", true); 90 51 } 91 52 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/SolutionProgramView.Designer.cs
r9790 r9889 20 20 #endregion 21 21 22 using System.Windows.Forms;23 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; 24 23 25 24 namespace HeuristicLab.Problems.Robocode { 26 25 partial class SolutionProgramView { 27 private Panel panel;28 private GraphicalSymbolicExpressionTreeView graphTreeView;29 30 26 private void InitializeComponent() { 31 this. panel = new System.Windows.Forms.Panel();27 this.graphTreeView = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.GraphicalSymbolicExpressionTreeView(); 32 28 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 33 29 this.SuspendLayout(); … … 38 34 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 39 35 // 40 // panel36 // graphTreeView 41 37 // 42 this.panel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 38 this.graphTreeView.AllowDrop = true; 39 this.graphTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 43 40 | System.Windows.Forms.AnchorStyles.Left) 44 41 | System.Windows.Forms.AnchorStyles.Right))); 45 this.panel.Location = new System.Drawing.Point(3, 26); 46 this.panel.Name = "panel"; 47 this.panel.Size = new System.Drawing.Size(345, 190); 48 this.panel.TabIndex = 3; 42 this.graphTreeView.Caption = "Graphical SymbolicExpressionTree View"; 43 this.graphTreeView.Content = null; 44 this.graphTreeView.Location = new System.Drawing.Point(6, 26); 45 this.graphTreeView.Name = "graphTreeView"; 46 this.graphTreeView.ReadOnly = false; 47 this.graphTreeView.Size = new System.Drawing.Size(342, 190); 48 this.graphTreeView.TabIndex = 0; 49 49 // 50 50 // SolutionProgramView 51 51 // 52 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 53 this.Controls.Add(this.panel); 52 this.Controls.Add(this.graphTreeView); 54 53 this.Name = "SolutionProgramView"; 55 54 this.Size = new System.Drawing.Size(351, 219); 56 this.Controls.SetChildIndex(this.panel, 0);57 55 this.Controls.SetChildIndex(this.nameLabel, 0); 58 56 this.Controls.SetChildIndex(this.nameTextBox, 0); 59 57 this.Controls.SetChildIndex(this.infoLabel, 0); 58 this.Controls.SetChildIndex(this.graphTreeView, 0); 60 59 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 61 60 this.ResumeLayout(false); … … 63 62 64 63 } 64 65 private GraphicalSymbolicExpressionTreeView graphTreeView; 65 66 } 66 67 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/SolutionProgramView.cs
r9790 r9889 22 22 using System.Windows.Forms; 23 23 using HeuristicLab.Core.Views; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;25 24 using HeuristicLab.MainForm; 26 25 … … 36 35 public SolutionProgramView() { 37 36 InitializeComponent(); 38 this.graphTreeView = new GraphicalSymbolicExpressionTreeView();39 graphTreeView.Dock = DockStyle.Fill;40 panel.Controls.Add(graphTreeView);41 37 } 42 38 … … 49 45 } 50 46 } 51 52 47 } 53 48 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs
r9888 r9889 29 29 namespace HeuristicLab.Problems.Robocode { 30 30 public class Interpreter { 31 public static double EvaluateTankProgram(ISymbolicExpressionTree tree, string path) { 32 string interpretedProgram = InterpretProgramTree(tree.Root); 31 public static double EvaluateTankProgram(ISymbolicExpressionTree tree, string path, string robotName = null, bool showUI = false) { 32 if (robotName == null) 33 robotName = GenerateRobotName(); 34 35 string interpretedProgram = InterpretProgramTree(tree.Root, robotName); 33 36 string formattedPath = path.Replace("/", "\\"); 34 string outputname = "";35 37 36 38 try { 37 outputname = Guid.NewGuid().ToString(); 38 outputname = outputname.Remove(8, 1); 39 outputname = outputname.Remove(12, 1); 40 outputname = outputname.Remove(16, 1); 41 outputname = outputname.Remove(20, 1); 42 outputname = outputname.Remove(0, 1); 43 outputname = outputname.Insert(0, "R"); 44 45 string output = interpretedProgram.Replace("class output", "class " + outputname); 46 File.WriteAllText(path + "/robots/Evaluation/" + outputname + ".java", output, System.Text.Encoding.Default); 39 File.WriteAllText(path + "/robots/Evaluation/" + robotName + ".java", interpretedProgram, System.Text.Encoding.Default); 47 40 } 48 41 catch (Exception ex) { … … 52 45 ProcessStartInfo javaCompileInfo = new ProcessStartInfo(); 53 46 javaCompileInfo.FileName = "cmd.exe"; 54 javaCompileInfo.Arguments = "/C javac -cp " + formattedPath + "\\libs\\robocode.jar " + formattedPath + "\\robots\\Evaluation\\" + outputname + ".java"; 47 javaCompileInfo.Arguments = "/C javac -cp " + formattedPath + "\\libs\\robocode.jar " + 48 formattedPath + "\\robots\\Evaluation\\" + robotName + ".java"; 55 49 javaCompileInfo.RedirectStandardOutput = true; 56 50 javaCompileInfo.RedirectStandardError = true; … … 67 61 javaCompile.WaitForExit(); 68 62 if (javaCompile.ExitCode != 0) { 69 DeleteRobotFiles(path, outputname);63 DeleteRobotFiles(path, robotName); 70 64 throw new Exception("Compile Error: " + cmdOutput); 71 65 } … … 77 71 ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo(); 78 72 evaluateCodeInfo.FileName = "cmd.exe"; 79 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." + outputname + "* " + formattedPath + " false"; 73 evaluateCodeInfo.Arguments = "/C java -classpath " + formattedPath + "\\libs;" + formattedPath + 74 "\\libs\\robocode.core-1.8.1.0.jar;" + formattedPath + "\\libs\\robocode.jar;" + 75 formattedPath + "\\libs\\picocontainer-2.14.2.jar BattleRunner Evaluation." + 76 robotName + "* " + formattedPath; 77 if (showUI) 78 evaluateCodeInfo.Arguments += " true"; 79 80 80 evaluateCodeInfo.RedirectStandardOutput = true; 81 81 evaluateCodeInfo.RedirectStandardError = true; … … 87 87 evaluateCode.Start(); 88 88 evaluateCode.WaitForExit(); 89 89 90 if (evaluateCode.ExitCode != 0) { 90 DeleteRobotFiles(path, outputname);91 DeleteRobotFiles(path, robotName); 91 92 throw new Exception("Error running Robocode: " + evaluateCode.StandardError.ReadToEnd()); 92 93 } … … 102 103 } 103 104 finally { 104 DeleteRobotFiles(path, outputname);105 DeleteRobotFiles(path, robotName); 105 106 } 106 107 … … 116 117 } 117 118 118 public static string InterpretProgramTree(ISymbolicExpressionTreeNode node) { 119 private static string GenerateRobotName() { 120 // Robocode class names are 32 char max and 121 // Java class names have to start with a letter 122 string outputname = Guid.NewGuid().ToString(); 123 outputname = outputname.Remove(8, 1); 124 outputname = outputname.Remove(12, 1); 125 outputname = outputname.Remove(16, 1); 126 outputname = outputname.Remove(20, 1); 127 outputname = outputname.Remove(0, 1); 128 outputname = outputname.Insert(0, "R"); 129 return outputname; 130 } 131 132 public static string InterpretProgramTree(ISymbolicExpressionTreeNode node, string robotName) { 119 133 var tankNode = node; 120 134 while (!(tankNode.Symbol is Tank)) 121 135 tankNode = tankNode.GetSubtree(0); 122 return ((CodeNode)tankNode.Symbol).Interpret(tankNode, tankNode.Subtrees); 136 137 string result = ((CodeNode)tankNode.Symbol).Interpret(tankNode, tankNode.Subtrees); 138 result = result.Replace("class output", "class " + robotName); 139 return result; 123 140 } 124 141 }
Note: See TracChangeset
for help on using the changeset viewer.