Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeEvaluator.cs @ 10711

Last change on this file since 10711 was 9971, checked in by ascheibe, 11 years ago

#2069 added a view for displaying/reloading enemies

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.Robocode {
32  [StorableClass]
33  [Item("Robocode Evaluator", "Evaluator for the Robocode GP problem.")]
34  public class RobocodeEvaluator : SingleSuccessorOperator, ISingleObjectiveEvaluator {
35    private const string QualityParameterName = "Quality";
36    private const string TankProgramParameterName = "TankProgram";
37    private const string RobocodePathParamaterName = "RobocodePath";
38    private const string NrOfRoundsParameterName = "NrOfRounds";
39    private const string EnemiesParameterName = "Enemies";
40
41    #region Parameters
42    public ILookupParameter<DoubleValue> QualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
44    }
45    public ILookupParameter<ISymbolicExpressionTree> TankProgramParameter {
46      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[TankProgramParameterName]; }
47    }
48    public ILookupParameter<DirectoryValue> RobocodePathParameter {
49      get { return (ILookupParameter<DirectoryValue>)Parameters[RobocodePathParamaterName]; }
50    }
51    public ILookupParameter<IntValue> NrOfRoundsParameter {
52      get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
53    }
54    public ILookupParameter<EnemyCollection> EnemiesParameter {
55      get { return (ILookupParameter<EnemyCollection>)Parameters[EnemiesParameterName]; }
56    }
57    #endregion
58
59    [StorableConstructor]
60    protected RobocodeEvaluator(bool deserializing) : base(deserializing) { }
61    protected RobocodeEvaluator(RobocodeEvaluator original, Cloner cloner)
62      : base(original, cloner) { }
63
64    public RobocodeEvaluator() {
65      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The solution quality of the Robocode tank program."));
66      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(TankProgramParameterName, "The Robocode tank program to evaluate represented as a symbolic expression tree."));
67      Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
68      Parameters.Add(new LookupParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent."));
69      Parameters.Add(new LookupParameter<EnemyCollection>(EnemiesParameterName, "The enemies that should be battled."));
70    }
71
72    public override IOperation Apply() {
73      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
74      string path = RobocodePathParameter.ActualValue.Value;
75      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path, EnemiesParameter.ActualValue, null, false, NrOfRoundsParameter.ActualValue.Value));
76
77      return base.Apply();
78    }
79
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new RobocodeEvaluator(this, cloner);
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.