Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/01/13 12:08:25 (11 years ago)
Author:
jkarder
Message:

#2069:

  • refactored grammar and symbols
  • fixed cloning and storable ctors
  • fixed plugin dependencies
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Modulus.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Modulus : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Modulus : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Modulus(bool deserializing) : base(deserializing) { }
    40     private Modulus(Modulus original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Modulus(bool deserializing) : base(deserializing) { }
     43    protected Modulus(Modulus original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Modulus()
    4646      : base("Modulus", "Modulus operator.") {
    47       this.Prefix = "%";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" % ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
Note: See TracChangeset for help on using the changeset viewer.