Exemple #1
0
        public void NextTest()
        {
            EntityRandom random = new EntityRandom(0);

            TestIntBuckets(random, 2);
            TestIntBuckets(random, 10);
            TestIntBuckets(random, 100);
        }
Exemple #2
0
            public static void CheckRandom(EntityRandom random, string at)
            {
                int i0 = random.Next(), i1 = random.Next(), i2 = random.Next();

                if (i0 == i1 && i1 == i2)
                {
                    throw new Exception("Random generator is out of whack: " + at);
                }
            }
Exemple #3
0
        private static void TestIntBuckets(EntityRandom random, int numBuckets)
        {
            int[] count   = new int[numBuckets];
            int   numRuns = 1000 * count.Length;

            for (int i = 0; i < numRuns; i++)
            {
                int n = random.Next(count.Length);
                Assert.IsTrue(n >= 0 && n < count.Length);
                count[n]++;
            }
            CheckEvenDistribution(count, numRuns);
        }
Exemple #4
0
        public void NextFloatTest()
        {
            EntityRandom random = new EntityRandom(new Random().Next());

            int[] count   = new int[1000];
            int   numRuns = 10000 * count.Length;

            for (int i = 0; i < numRuns; i++)
            {
                float f      = random.NextFloat();
                int   bucket = Math.Min((int)(f * count.Length), count.Length - 1);
                count[bucket]++;
            }
            CheckEvenDistribution(count, numRuns);
        }
Exemple #5
0
        static IEnumerable <Entity> MakeGrid2D(int horizontalResolution)
        {
            EntityRandom random = new EntityRandom(1024);

            for (int x = 0; x < horizontalResolution; x++)
            {
                for (int y = 0; y < horizontalResolution; y++)
                {
                    yield return(new Entity(
                                     new EntityID(Guid.NewGuid(), Simulation.MySpace.DeRelativate(new Vec3(0.5f + x, 0.5f + y, 0) / horizontalResolution)),
                                     Vec3.Zero,
                                     new Habitat(random),                      //check that this doesn't actually cause a fault (should get clamped)
                                     null));
                }
            }
        }
Exemple #6
0
        public void NextBoolTest()
        {
            EntityRandom random = new EntityRandom(new Random().Next());

            int[] buckets = new int[2];
            for (int i = 0; i < 2000; i++)
            {
                if (random.NextBool())
                {
                    buckets[1]++;
                }
                else
                {
                    buckets[0]++;
                }
            }
            CheckEvenDistribution(buckets, 2000);
        }
Exemple #7
0
            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);
            }
Exemple #8
0
 protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool isInconsistent)
 {
     newState.NewPosition = currentState.ID.Position + Motion;
 }
Exemple #9
0
            protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, Shard.EntityRanges ranges, bool isInconsistent)
            {
#if STATE_ADV
                throw new NotImplementedException();
#else
                newState.Broadcast(0, Helper.SerializeToArray(currentState.ID));
                newState.FlagInconsistent();
#endif
            }
Exemple #10
0
            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");
                    }
                }
            }
Exemple #11
0
 protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom random, EntityRanges ranges, bool isInconsistent)
 {
     newState.Broadcast(0, null);
 }
Exemple #12
0
            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;
                }
            }
Exemple #13
0
    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);
    }
Exemple #14
0
 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));
 }
Exemple #15
0
 protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool isInconsistent)
 {
     state++;
 }
Exemple #16
0
 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));
     }
 }
Exemple #17
0
 protected override void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool locationIsInconsistent)
 {
     numReceived += Helper.Length(currentState.InboundMessages);
 }
Exemple #18
0
	public override void Evolve(ref NewState newState, Entity currentState, int generation, EntityRandom random, EntityRanges ranges)
	{
		if (generation % 3 == 0)	//move bugs
		{
			newState.Broadcast(
			
		}
		
		
		
		
		
	}
Exemple #19
0
 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));
             }
         }
     }
 }