Ejemplo n.º 1
0
                public void AddTo(List <EntityMessage> messages, EntityRanges ranges, Vec3 entityLocation)
                {
                    var ar = inMessages.ToArray();

                    Array.Sort(ar, (a, b) => a.Key.CompareTo(b.Key));
                    int lastID = -1;

                    foreach (var p in ar)
                    {
                        if (p.Key.orderID != lastID)
                        {
                            messages.Add(p.Value);
                        }
                        lastID = p.Key.orderID;
                    }
                }
Ejemplo n.º 2
0
        public static void Configure(ShardID addr, BaseDB.ConfigContainer config, bool forceAllLinksPassive)
        {
            CSLogicProvider.AsyncFactory = DB.GetLogicProviderAsync;

            ID      = addr;
            gridExt = config.extent;
            Ranges  = ToRanges(config);
            MySpace = SDToBox(addr.XYZ, config.extent);


            InconsistencyCoverage.CommonResolution = (int)Math.Ceiling(1f / Ranges.R);

            if (Extent.ReplicaLevel > 1)
            {
                siblings = Neighborhood.NewSiblingList(addr, Extent.ReplicaLevel, forceAllLinksPassive);
            }
            neighbors = Neighborhood.NewNeighborList(addr, Extent.XYZ, forceAllLinksPassive);
        }
Ejemplo n.º 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);
            }
Ejemplo n.º 4
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
            }
Ejemplo n.º 5
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");
                    }
                }
            }
Ejemplo n.º 6
0
        protected override void Evolve(ref Actions actions, Entity currentState, int generation, EntityRandom random, EntityRanges ranges, bool isInconsistent)
        {
#if STATE_ADV
            actions.SuppressAdvertisements = true;
#endif
            int  zero    = 0;
            bool killBug = predator.ExecuteMotion(ref actions, currentState, generation - 1, random, bug.AnimalSize, ref zero);

            food += random.NextFloat(maxFoodProduction);

            if (bug.HasAnimal)
            {
                if (killBug)
                {
                    predator.Consume(bug);
                }
                else
                {
                    float delta = Math.Min(food, 10f);
                    bug.Consume(delta);
                    food -= delta;
                    food  = Math.Max(0, food);
                    if (bug.AnimalSize > 10f)
                    {
                        bug.AnimalSize = 0.001f;
                        spawn          = 5;
                    }
                }
            }

            bug.ExecuteMotion(ref actions, currentState, generation, random, food, ref spawn);
        }
Ejemplo n.º 7
0
        protected override void Evolve(ref Actions actions, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool locationIsInconsistent)
        {
            try
            {
                FinishLoading(currentState.ID, TimeSpan.FromMilliseconds(1));
                nestedLogic.Execute(ref actions, currentState, generation, randomSource, ranges, locationIsInconsistent);

                actions.ReplaceInstantiations(inst =>
                {
                    if (inst.logic != null && !(inst.logic is DynamicCSLogic))
                    {
                        inst.logic = new DynamicCSLogic(provider, inst.logic);
                    }
                    return(inst);
                });
            }
            catch (ExecutionException ex)
            {
                if (constructor != null)
                {
                    throw new ExecutionException(currentState.ID, constructor.AssemblyName + "." + constructor.LogicName + ": " + ex.Message, ex);
                }
                throw new ExecutionException(currentState.ID, provider.AssemblyName + "." + nestedLogic.GetType() + ": " + ex.Message, ex);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Evolves the local state, potentially generating some modifications to the base entity.
 /// The method must not change any local variables relevant to evolution. All entity modifications are limited to changes in.
 /// Evolution must be deterministic.
 /// <paramref name="newState"/>.
 /// </summary>
 /// <param name="newState">Modifications go here</param>
 /// <param name="currentState">Current entity state</param>
 /// <param name="generation">Evolution generation index, starting from 0</param>
 /// <param name="randomSource">Random source to be used exclusively for random values</param>
 /// <param name="ranges">Simulation range configuration</param>
 /// <param name="locationIsInconsistent">Set true if the location of the local entity is currently considered possibly inconsistent</param>
 protected abstract void Evolve(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool locationIsInconsistent);
Ejemplo n.º 9
0
        private int myGeneration;               //cannot initialize with anything explicitly. Assume is 0

        public void Execute(ref Actions newState, Entity currentState, int generation, EntityRandom randomSource, EntityRanges ranges, bool locationIsInconsistent)
        {
            VerifyGeneration(generation);
            Evolve(ref newState, currentState, generation, randomSource, ranges, locationIsInconsistent);
            myGeneration = generation + 2;
            //Console.WriteLine(this + "->" + myGeneration);
        }