Exemple #1
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 #2
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 #3
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);
            }