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 UpdateBrain(FishSimulator.Delta delta, Perception perception)
        {
            var t = delta.deltaTime;

            this.physicalState.UpdateTime(t);
            this.mentalState.UpdateState(t, this.physicalState, perception.GetSensorData());

            this.currentIntension = this.intensionGenerator.Generate(perception, this.habits, this.mentalState, this.physicalState, t);
            this.currentDesire.UpdateDesire(this.mentalState, this.currentIntension);
        }