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); }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, Shard.EntityRanges ranges, bool isInconsistent) { while (newState.NewPosition == currentState.ID.Position) { //newState.NewPosition = ranges.World.Clamp(currentState.ID.Position + random.NextVec3(-ranges.M, ranges.M)); newState.NewPosition = currentState.ID.Position + randomSource.NextVec3(-ranges.Motion, ranges.Motion); if (Vec3.GetChebyshevDistance(newState.NewPosition, currentState.ID.Position) > ranges.Motion) { throw new Exception("Pre-clamp motion range exceeded"); } newState.NewPosition = ranges.World.Clamp(newState.NewPosition); if (Vec3.GetChebyshevDistance(newState.NewPosition, currentState.ID.Position) > ranges.Motion) { throw new Exception("Post-clamp motion range exceeded"); } } }
protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom random, Shard.EntityRanges ranges) { CheckRandom(random, "started"); if (isConsistent && currentState.Contacts != null) { foreach (var c in currentState.Contacts) { var dist = Vec3.GetChebyshevDistance(c.ID.Position, currentState.ID.Position); Assert.IsTrue(dist <= Simulation.SensorRange); if (!IsConsistent(c.Appearances)) { isConsistent = false; break; } } } newState.AddOrReplace(new ConsistencyAppearance(isConsistent)); //is consistent? if (!Simulation.MySpace.Contains(currentState.ID.Position)) { throw new IntegrityViolation(currentState + ": not located in simulation space " + Simulation.MySpace); } int cnt = 0; do { Vec3 draw = random.NextVec3(-ranges.M, ranges.M); newState.NewPosition = ranges.World.Clamp(currentState.ID.Position + draw); if (++cnt > 1000) { throw new Exception("Exceeded 1000 tries, going from " + currentState.ID.Position + ", by " + M + "->" + draw + " in " + Simulation.MySpace + "; " + random.Next() + ", " + random.Next() + ", " + random.Next()); } }while (newState.NewPosition == currentState.ID.Position); }
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)); }