/// <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; } } }
public Configuration() { EnvironmentSettings = new Environment(); AgentSettings = new Agent(); TagSettings = new Tag(); ResourceSettings = new Resource(); }
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; }
public static Tag New(Tag tag) { if (tag == null) throw new ArgumentNullException("tag"); return new Tag(tag.Data.Select(r => r.Label).ToArray()); }
/// <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; }
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."); } }