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);
        }