Пример #1
0
        public void UpdateState(float t, PhysicalState physical, SensorData sensor)
        {
            var closestFood = sensor.GetClosestByType(ObjectType.Food);
            var closestMate = sensor.GetClosestByType(ObjectType.Mate);

            this.H(t, physical, closestFood);
            this.L(t, physical, closestMate);
            this.F(t, physical, sensor.GetVisiable(ObjectType.Predator));
        }
Пример #2
0
        private float L(float t, PhysicalState ps, SensorObject target)
        {
            var Ht              = this.hunger;
            var internalUrge    = ps.Lx(ps.timeSinceLastMating) * (1 - Ht);
            var externalStimuli = this.Sl(target);

            var L = math.min(internalUrge + externalStimuli, 1);

            this.libido = L;

            return(this.libido);
        }
Пример #3
0
        private float H(float t, PhysicalState ps, SensorObject target)
        {
            var internalUrge    = 1 - ps.foodEaten * ps.Rx(ps.timeSinceLastMeal) / ps.appetite;
            var externalStimuli = ps.alphah * this.Sh(target);


            var H = math.min(internalUrge + externalStimuli, 1);

            this.hunger = H;

            return(this.hunger);
        }
Пример #4
0
        private float F(float t, PhysicalState ps, List <SensorObject> targets)
        {
            var externalStimuli = 0f;
            var internalUrge    = 0;

            foreach (var p in targets)
            {
                externalStimuli += ps.Fi(p.distance);
            }

            var F = math.min(internalUrge + externalStimuli, 1);

            this.fear = F;

            return(this.fear);
        }
        public Intension Generate(Perception perception, Habits habits, MentalState mental, PhysicalState ps, float t)
        {
            Intension intension  = default;
            var       sensorData = perception.GetSensorData();
            var       distance   = sensorData.closestDangerObj == null ? -1 : sensorData.closestDangerObj.distance;

            if (distance > 0)
            {
                var mono = sensorData.closestDangerObj.obj as MonoBehaviour;
                intension = new AvoidIntension(mono.gameObject);

                if (this.intensionStack.Count == 0 || this.intensionStack.Last.Value.IntensionType != Intension.Type.Avoid)
                {
                    this.intensionStack.AddLast(intension);
                }
            }
            else
            {
                //fear of most dangerous predator m
                var p  = sensorData.GetClosestByType(ObjectType.Predator);
                var Fm = p != null?ps.Fi(p.distance) : 0;

                var F = mental.fear;
                if (F > this.f0)
                {
                    if (Fm < this.f1 && habits.schooling)
                    {
                        intension = new SchoolIntension();
                    }
                    else
                    {
                        var mono = p.obj as MonoBehaviour;
                        intension = new EscapedIntension(mono.gameObject);
                    }
                }
                else
                {
                    if (this.IsLastEatOrMate())
                    {
                        intension = this.intensionStack.Last.Value;
                        this.intensionStack.RemoveLast();
                    }
                    else
                    {
                        intension = this.GenerateNewIntension(perception, habits, mental, ps, t);
                    }
                }
            }

            if (this.intensionStack.Count > 1)
            {
                this.intensionStack.RemoveFirst();
            }


            LogTool.AssertIsTrue(intension != null);

            return(intension);
        }
        protected Intension GenerateNewIntension(Perception perception, Habits habits, MentalState mental, PhysicalState ps, float t)
        {
            Intension intension = default;
            var       H         = mental.hunger;
            var       L         = mental.libido;

            if (this.r < math.max(H, L))
            {
                if (H == L)
                {
                    if (ThreadSafeRandom.NextFloat() > 0.5f)
                    {
                        intension = new EatIntension();
                    }
                    else
                    {
                        intension = new MateIntension();
                    }
                }
                else
                {
                    if (H > L)
                    {
                        intension = new EatIntension();
                    }
                    else
                    {
                        intension = new MateIntension();
                    }
                }
            }
            else
            {
                //perception.temperatureSensor;
                //perception.visionSensor;

                //generate wonder or leave
                intension = new WanderIntension();
            }

            return(intension);
        }