1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
22 | using System.IO;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Problems.GeneticProgramming.Robocode;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Problems.GeneticProgramming.Views.Robocode {
|
---|
28 | public partial class BattleRunnerDialog : Form {
|
---|
29 | public int NrOfRounds {
|
---|
30 | get { return (int)nrOfRoundsNumericUpDown.Value; }
|
---|
31 | set { nrOfRoundsNumericUpDown.Value = value; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public EnemyCollection Enemies {
|
---|
35 | get { return enemyCollectionView.Content; }
|
---|
36 | set { enemyCollectionView.Content = value; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public BattleRunnerDialog(Solution solution) {
|
---|
40 | InitializeComponent();
|
---|
41 | errorProvider.SetIconAlignment(robocodePathTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
42 | errorProvider.SetIconPadding(robocodePathTextBox, 2);
|
---|
43 | nrOfRoundsNumericUpDown.Maximum = int.MaxValue;
|
---|
44 | NrOfRounds = solution.NrOfRounds;
|
---|
45 | Enemies = (EnemyCollection)solution.Enemies.Clone(new Cloner());
|
---|
46 | robocodePathTextBox.Text = Enemies.RobocodePath;
|
---|
47 | }
|
---|
48 |
|
---|
49 | private void searchButton_Click(object sender, System.EventArgs e) {
|
---|
50 | var result = folderBrowserDialog.ShowDialog(this);
|
---|
51 | if (result == DialogResult.OK)
|
---|
52 | Enemies.RobocodePath = robocodePathTextBox.Text = folderBrowserDialog.SelectedPath;
|
---|
53 | }
|
---|
54 |
|
---|
55 | private void runInRobocodeButton_Click(object sender, System.EventArgs e) {
|
---|
56 | DialogResult = DialogResult.OK;
|
---|
57 | Close();
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void robocodePathTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
61 | string robocodePath = robocodePathTextBox.Text;
|
---|
62 | if (string.IsNullOrEmpty(robocodePath)) {
|
---|
63 | e.Cancel = true;
|
---|
64 | errorProvider.SetError(robocodePathTextBox, "Robocode directory has to be set");
|
---|
65 | robocodePathTextBox.SelectAll();
|
---|
66 | return;
|
---|
67 | }
|
---|
68 | var info = new DirectoryInfo(robocodePath);
|
---|
69 | if (!info.Exists) {
|
---|
70 | e.Cancel = true;
|
---|
71 | errorProvider.SetError(robocodePathTextBox, "This directory does not exist");
|
---|
72 | robocodePathTextBox.SelectAll();
|
---|
73 | return;
|
---|
74 | }
|
---|
75 | Enemies.RobocodePath = robocodePathTextBox.Text;
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void robocodePathTextBox_Validated(object sender, System.EventArgs e) {
|
---|
79 | errorProvider.SetError(robocodePathTextBox, string.Empty);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|