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);
        }
示例#2
0
        public void UpdateDesire(MentalState mental, Intension intension)
        {
            this.intensionType = intension.IntensionType;

            var ti = 1f;

            switch (intension.IntensionType)
            {
            case Intension.Type.Escape: ti = mental.fear; break;

            case Intension.Type.Eat: ti = mental.hunger; break;

            case Intension.Type.Mate: ti = mental.libido; break;

            default: ti = 1; break;
            }
            this.avoid = 1;
            this.fear  = mental.fear / ti;
            this.eat   = mental.hunger / ti;
            this.mate  = mental.libido / ti;
        }
        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);
        }