コード例 #1
0
        /// <summary>
        /// Create a new unique identifier from a list of tags.
        /// </summary>
        /// <param name="type">
        /// The type of object that the identifier is for.
        /// </param>
        /// <param name="tags">
        /// A list of Tag objects and nulls, where null specifies the delimiter
        /// between agent tags in the case of a multiagent.
        /// </param>
        public UniqueIdentifier(IdentityType type, Tag[] tags)
        {
            this.type = type;

            int totalSize = tags.Sum(x => (x==null) ? 0 : x.Data.Count) + tags.Length - 1;
            this.genome = new Resource[totalSize];
            int i = 0;
            bool isFirst = true;
            foreach (var tag in tags)
            {
                // Pad with a null for every new tag after the first
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    this.genome[i++] = null;
                }

                if (tag != null)
                {
                    Array.Copy(tag.Data.ToArray(), 0, this.genome, i, tag.Data.Count);
                    i += tag.Data.Count;
                }
            }
        }
コード例 #2
0
 public Configuration()
 {
     EnvironmentSettings = new Environment();
     AgentSettings = new Agent();
     TagSettings = new Tag();
     ResourceSettings = new Resource();
 }
コード例 #3
0
        private GridResourceNode(Tag offense, Tag defense, Tag exchange)
        {
            RenewableResources = new List<Resource>();
            Reservoir = new List<Resource>();

            this.Offense = offense;
            this.Defense = defense;
            this.Exchange = exchange;

            Id = new UniqueIdentifier(IdentityType.ResourceNode, new[] { this.Offense, this.Defense, this.Exchange });
            Source = null;
        }
コード例 #4
0
ファイル: Tag.cs プロジェクト: andrewanderson/Web-Critters
        public static Tag New(Tag tag)
        {
            if (tag == null) throw new ArgumentNullException("tag");

            return new Tag(tag.Data.Select(r => r.Label).ToArray());
        }
コード例 #5
0
ファイル: Tag.cs プロジェクト: andrewanderson/Web-Critters
        /// <summary>
        /// Generates a new random tag of random size within the specified bounds.
        /// </summary>
        public static Tag New(int minLength, int maxLength, bool allowWildCard)
        {
            if (minLength < 1 || minLength > MaxSize || minLength > maxLength) throw new ArgumentOutOfRangeException("minLength");
            if (maxLength < 1 || maxLength > MaxSize) throw new ArgumentOutOfRangeException("maxLength");

            Tag newTag = new Tag();
            newTag.Data = new List<Resource>();

            int length = minLength + RandomProvider.Next(maxLength - minLength + 1);
            for (int i = 0; i < length; i++)
            {
                newTag.Data.Add(Resource.Random(allowWildCard));
            }

            return newTag;
        }
コード例 #6
0
 public void SetTagByIndex(int index, Tag value)
 {
     switch (index)
     {
         case (int)CellTagIndex.Offense:
             Offense = value;
             break;
         case (int)CellTagIndex.Defense:
             Defense = value;
             break;
         case (int)CellTagIndex.Exchange:
             Exchange = value;
             break;
         case (int)CellTagIndex.Mating:
             Mating = value;
             break;
         default:
             throw new ArgumentOutOfRangeException("index", index, "No tag with specified index.");
     }
 }