public SimEntity CreateEntity(string genome) { var e = new SimEntity(); int nodeCounter = 0; var components = genome.Split('|'); foreach (var c in components) { var component = new SimComponent(); var data = c.Split(';'); if (data[0] == "N") { // node // e.g. "N;1.35" component.Attributes = new float[1]; component.Attributes[0] = float.Parse(data[1]); // friction component.Name = $"Node{++nodeCounter}"; } else { // connection // e.g. "C;2.0;0.5;1.0;1;2" component.Attributes = new float[3]; component.Attributes[0] = float.Parse(data[1]); // length component.Attributes[1] = float.Parse(data[2]); // contraction component.Attributes[2] = float.Parse(data[3]); // period component.Name = $"Connection{data[4]}-{data[5]}"; } e.Components.Add(component); } return(e); }
public override void CloneFrom(SimComponent component) { var other = (SAInteract)component; InteractionRange = other.InteractionRange; InteractionInterval = other.InteractionInterval; interactionTime = other.interactionTime; base.CloneFrom(component); }
public override void CloneFrom(SimComponent component) { var other = (SCResourceSite)component; if (Resources == null) Resources = new ResourceCollection(); Resources.CloneFrom(other.Resources); DieOnDeplete = other.DieOnDeplete; base.CloneFrom(component); }
public SimEntity CreateEntity() { var entity = new SimEntity(); // generate random node count var nodeCount = r.Next(MIN_NODES, MAX_NODES + 1); // max connections = n * (n-1) / 2 var maxConnections = (nodeCount * (nodeCount - 1)) / 2; var connectionCount = r.Next(nodeCount - 1, maxConnections + 1); entity.Name = $"N{nodeCount}C{connectionCount}"; entity.Id = ++eid; for (int n = 0; n < nodeCount; n++) { var comp = new SimComponent() { Kind = NODE_KIND, Name = $"Node{n}", Attributes = new float[] { RandomFriction() } // range 0.5 - 1.5 }; entity.Components.Add(comp); } int connectionCounter = 0; for (int n = 0; n < nodeCount - 1; n++) { for (int i = n + 1; i < nodeCount; i++) { var comp = new SimComponent() { Kind = CONNECTION_KIND, Name = $"{n}-{i}", Attributes = new float[3] { RandomLength(), RandomContraction(), RandomPeriod(), } }; comp.CustomData = new int[2] { n, i }; entity.Components.Add(comp); if (++connectionCounter >= connectionCount) { // force both loops to exit i = nodeCount; n = nodeCount; } } } return(entity); }
public override void CloneFrom(SimComponent component) { var other = (SAGather)component; Capacity = other.Capacity; GatherAmount = other.GatherAmount; DropRange = other.DropRange; DropTime = other.DropTime; HoldingAmount = other.HoldingAmount; HoldingType = other.HoldingType; base.CloneFrom(component); }
private static void OnSimRegistered(SimComponent instance, int handle, Action <int> static_unregister) { if ((UnityEngine.Object)instance != (UnityEngine.Object)null) { instance.simHandle = handle; instance.OnSimRegistered(); } else { static_unregister(handle); } }
static public SimComponent Clone(SimComponent c) { var clone = new SimComponent(); clone.Kind = c.Kind; clone.Name = c.Name; clone.Attributes = (float[])c.Attributes.Clone(); if (c.CustomData != null) { clone.CustomData = (int[])c.CustomData.Clone(); } return(clone); }
public void PassValueToNext(SimComponent destinationComp, float valueToPass) { if ((double)this.nextValue < (double)valueToPass) { valueToPass = this.nextValue; } float num = destinationComp.max - destinationComp.nextValue; if ((double)valueToPass > (double)num) { valueToPass = num; } this.AddNextValue(-valueToPass); destinationComp.AddNextValue(valueToPass); }
internal void Update(IEnumerable <ComponentUpdate> updates) { foreach (ComponentUpdate update in updates) { SimComponent component = update.component; ComponentTypeName type = component.GetType().Name; for (int i = 0; i < components[type].Count; i++) { if (components[type][i].EntityID != component.EntityID) { continue; } components[type][i] = component; } } }
public void AssertEquals(Snapshot other) { if (components.Count != other.components.Count) { throw new Exception("Component count mismatch"); } foreach (ComponentTypeName name in components.Keys) { if (!other.components.ContainsKey(name)) { throw new Exception("Component not found: " + name); } for (int i = 0; i < components[name].Count; i++) { SimComponent thisComponent = components[name][i]; SimComponent otherComponent = other.components[name][i]; Type componentType = thisComponent.GetType(); // Compare SimComponent property values PropertyInfo[] props = componentType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); foreach (PropertyInfo prop in props) { object val1 = prop.GetValue(thisComponent); object val2 = prop.GetValue(otherComponent); if (!Equals(val1, val2)) { throw new Exception(string.Format("Component {0} property '{1}' value not equal. Expected: {2}, actual: {3}", name, prop.Name, val1, val2)); } } // Compare SimComponent field values FieldInfo[] fields = componentType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); foreach (FieldInfo field in fields) { object val1 = field.GetValue(thisComponent); object val2 = field.GetValue(otherComponent); if (!Equals(val1, val2)) { throw new Exception(string.Format("Component {0} field '{1}' value not equal. Expected: {2}, actual: {3}", name, field.Name, val1, val2)); } } } } }
public SimEntity CloneEntity(SimEntity e) { var entity = new SimEntity(); entity.Name = e.Name; entity.Generation = e.Generation; entity.Species = e.Species; entity.Species = e.Species; entity.Id = ++eid; if (e.CustomData != null) { entity.CustomData = (int[])e.CustomData.Clone(); } foreach (var c in e.Components) { var clone = SimComponent.Clone(c); entity.Components.Add(clone); } return(entity); }
public override void CloneFrom(SimComponent component) { var other = (SAMove)component; Speed = other.Speed; base.CloneFrom(component); }
public ComponentUpdate(SimComponent component) { this.component = component; }
public override void CloneFrom(SimComponent component) { var other = (SAAttack)component; Damage = other.Damage; base.CloneFrom(component); }