public static Removal RandomRemoval(EntityRanges ranges) { var id = RandomID(ranges.World); var id2 = new EntityID(Guid.NewGuid(), ClampedDestination(id.Position, ranges)); return(new Removal(id, id2)); }
public static Motion RandomMotion(EntityRanges range) { var id = RandomID(range.World); var to = ClampedDestination(id.Position, range); return(new Motion(id, to, #if STATE_ADV RandomAppearance(), #endif null, RandomLogic())); }
public static Instantiation RandomInstantiation(EntityRanges ranges) { var id = RandomID(ranges.World); var inst = ClampedDestination(id.Position, ranges); return(new Instantiation(id, inst, #if STATE_ADV RandomAppearance(), #endif null, RandomLogic())); }
public static EntityChangeSet RandomSet(EntityRanges ranges) { EntityChangeSet rs = new EntityChangeSet(); int numInserts = random.Next(0, 3); for (int i = 0; i < numInserts; i++) { rs.Add(RandomInstantiation(ranges)); } int numRemoval = random.Next(0, 3); for (int i = 0; i < numRemoval; i++) { rs.Add(RandomRemoval(ranges)); } int numMotions = random.Next(0, 3); for (int i = 0; i < numMotions; i++) { rs.Add(RandomMotion(ranges)); } int numBroadcasts = random.Next(0, 3); for (int i = 0; i < numBroadcasts; i++) { rs.Add(RandomBroadcast(ranges)); } int numMessages = random.Next(0, 3); for (int i = 0; i < numMessages; i++) { rs.Add(RandomMessage(ranges.World)); } return(rs); }
public static Vec3 ClampedDestination(Vec3 origin, EntityRanges range) { return(range.World.Clamp(random.NextVec3(Box.Centered(origin, range.Motion)))); }
public static Broadcast RandomBroadcast(EntityRanges ranges) { return(new Broadcast(RandomID(ranges.World), random.Next(16), random.NextFloat(0.0001f, ranges.Transmission), random.Next(3), RandomByteArray(true))); }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom random, EntityRanges ranges, bool isInconsistent) { newState.Broadcast(0, null); }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool isInconsistent) { if (!amPong) { newState.Broadcast(0, Helper.SerializeToArray(p.Increment())); amPong = true; p = p.Increment(); } else { PingPacket data = null; if (currentState.InboundMessages != null) { foreach (var m in currentState.InboundMessages) { if (m.Sender == currentState.ID) { continue; } data = Helper.Deserialize(m.Payload) as PingPacket; if (data != null) { break; } } } if (data == null) { return; } newState.Broadcast(0, Helper.SerializeToArray(data.Increment())); p = data; } }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool isInconsistent) { state++; }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom random, EntityRanges ranges, bool isInconsistent) { newState.NewPosition = ranges.World.Clamp(currentState.ID.Position + random.NextVec3(-ranges.Motion, ranges.Motion)); }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool locationIsInconsistent) { for (int i = 0; i < numMessages; i++) { newState.Broadcast(0, null, ranges.R / numMessages * (1.5f + i)); } }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool locationIsInconsistent) { numReceived += Helper.Length(currentState.InboundMessages); }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool isInconsistent) { newState.NewPosition = currentState.ID.Position + Motion; }
public override void Evolve(ref NewState newState, Entity currentState, int generation, EntityRandom random, EntityRanges ranges) { if (generation % 3 == 0) //move bugs { newState.Broadcast( } }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom random, EntityRanges ranges, bool isInconsistent) { inertia += random.NextVec3(-ranges.Motion / 10, ranges.Motion / 10); foreach (var msg in currentState.EnumInboundEntityMessages(0)) { var delta = currentState.ID.Position - msg.Sender.Position; //var dist = delta.Length; inertia += delta.Normalized() * (ranges.Motion / 3); } inertia = inertia.Clamp(-ranges.Motion, ranges.Motion); var newPos = currentState.ID.Position + inertia; float iX = inertia.X, iY = inertia.Y, iZ = inertia.Z; newState.NewPosition = new Vec3( CheckAxis(newPos.X, ranges.World.X, ref iX), CheckAxis(newPos.Y, ranges.World.Y, ref iY), CheckAxis(newPos.Z, ranges.World.Z, ref iZ) ); inertia = new Vec3(iX, iY, iZ); }
public ExecutionContext(EntityRanges ranges, Box localSimulationSpace) { Ranges = ranges; LocalSpace = localSimulationSpace; }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool isInconsistent) { if (currentState.InboundMessages != null) { foreach (var m in currentState.InboundMessages) { if (!m.Sender.IsEntity) { if (m.IsBroadcast) { newState.Send(m.Sender, 0, currentState.ID.Guid.ToByteArray()); continue; } Assert.AreEqual(m.Payload.Length, 4); float f = BitConverter.ToSingle(m.Payload, 0); float f2 = (float)Math.Sin(f); Console.WriteLine("@" + generation + ": " + f + "->" + f2); newState.Send(m.Sender, 1, BitConverter.GetBytes(f2)); } } } }