Пример #1
0
 public void InitializeMover(MoveData moveData)
 {
     if (moveData != null)
     {
         _walkingThought = new WalkingThought(this, moveData);
     }
 }
Пример #2
0
        //
        // Do Stuff
        //

        public virtual void MoveTo(IThought initiatingThought, IPosition destination)
        {
            // are we trying to go to the same place?
            if (ActionManager.FindOne(ActionType.Move) is BasicMovementAction ma)
            {
                // we have a movement action
                if (ma.FinalDestination == destination)
                {
                    // we're already going there
                    return;
                }
            }

            // stop going where we *were* going
            ActionManager.Remove(ActionType.Move);

            // now go somewhere else
            Destination = destination;
            double[] steps = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };

            double xRange = destination.Value.X - Position.Value.X;
            double yRange = destination.Value.Y - Position.Value.Y;

            // add some actions to iterate there
            foreach (double fraction in steps)
            {
                ActionManager.Push(new BasicMovementAction(initiatingThought, new BasicPosition(
                                                               Position.Value.X + (fraction * xRange),
                                                               Position.Value.Y + (fraction * yRange)
                                                               )));
            }
        }
Пример #3
0
 public void InitializeAttacker(AttackData attackData)
 {
     if (attackData != null)
     {
         _attackingThought = new AttackingThought(this, attackData);
     }
 }
Пример #4
0
 public BasicMovementAction(IThought initiatingThought, IPosition destination)
     : base(initiatingThought, ActionType.Move, new Percent(_defaultPriority))
 {
     Destination = destination;
     if (initiatingThought is IMovementThought mt)
     {
         FinalDestination = mt.Destination;
     }
 }
Пример #5
0
 public BasicFoodThoughtViewModel(IThought thought) : base(thought)
 {
     if (thought is BasicFoodThought bft)
     {
         bft.Threshold.Value.Changed += Value_Changed;
     }
     else
     {
         throw new NotSupportedException($"{nameof(thought)} must be derived from BasicFoodThought");
     }
 }
Пример #6
0
        public virtual void MoveTo(IThought initiatingThought, IBuilding building)
        {
            // remove any Move or EnterBuilding actions
            ActionManager.Remove(ActionType.Move);
            ActionManager.Remove(ActionType.EnterBuilding);

            // Set our destination
            MoveTo(initiatingThought, building.Position);

            // a final thought to enter the building
            ActionManager.Push(new EnterBuildingAction(initiatingThought, building));
        }
        //public string Position => (Thought as BasicMovementThought)?.Destination?.Value?.ToString() ?? string.Empty;


        public BasicMovementThoughtViewModel(IThought thought) : base(thought)
        {
            if (thought is BasicMovementThought bmt)
            {
                if (bmt.Destination != null)
                {
                    bmt.DestinationChanged += Destination_Changed;
                }
            }
            else
            {
                throw new NotSupportedException($"{nameof(thought)} must be derived from BasicMovementThought");
            }
        }
Пример #8
0
    public void EnterThought(ThoughtType thoughtType)
    {
        if (thoughtType == CurrentThoughtType)
        {
            return;
        }

        IThought nextThought;

        switch (thoughtType)
        {
        case ThoughtType.Idle:
            nextThought = _idleThought;
            break;

        case ThoughtType.Walking:
            nextThought = _walkingThought;
            break;

        case ThoughtType.Attacking:
            nextThought = _attackingThought;
            break;

        default:
            throw new NotImplementedException("ThoughtType not implemented: " + thoughtType);
        }

        CurrentThoughtType = thoughtType;
        if (nextThought == null)
        {
            nextThought        = _idleThought;
            CurrentThoughtType = ThoughtType.Idle;
        }

        if (_currentThought != null)
        {
            _currentThought.Exit();
        }
        _currentThought = nextThought;
        _currentThought.Enter();
    }
 public ThoughtsController(IMapper mapper, IThought thought)
 {
     _thought = thought;
     _mapper  = mapper;
 }
Пример #10
0
 public BasicThoughtViewModel(IThought thought) => Thought = thought;
        //候補集合を初期化
        public void BuildCandidate(int neighbourNum, IThought thought)//ご近所の数と初期重要視度を渡されることで候補を生成
        {
            if (neighbourNum <= 0)
            {
                return;
            }

            //Sigma=Thought   PriorBelief=Thought   updateFunc=BeliefUpdater
            lock (CandidateLock)
            {
                //ご近所の数
                int dn = neighbourNum;

                //ご近所の数の2倍だけ作成
                candidates = new Candidate[2 * dn];

                double sigmaRight = thought.SigmaRight;
                double sigmaLeft  = thought.SigmaLeft;

                double impLvl = 0.5;
                // Jumpnum = 3, 2, 1と調べていく.
                for (int l = dn; l >= 0; l--)
                {
                    //importance levelを上げていって,beliefがしきい値を超えたときその値を使う.
                    for (; impLvl <= 1; impLvl += 0.001)
                    {
                        if (BeliefUpdater.updateFunc(thought.PriorBelief, impLvl, l) > sigmaRight)
                        {
                            Candidate newcan = new Candidate(l, impLvl);

                            //この重要視度で、逆側に行くときは、何ステップでいけるのか?
                            double tmpBelief = thought.PriorBelief;
                            int    count     = 0;
                            do
                            {
                                tmpBelief = BeliefUpdater.updateFunc(tmpBelief, 1 - impLvl);//逆では1-impLvl
                                count++;
                            } while (!(tmpBelief <= sigmaLeft));

                            newcan.OtherJumpNum = count;

                            candidates[l - 1] = newcan;
                            break;
                        }
                    }
                }

                impLvl = 0.5;
                for (int l = dn; l >= 0; l--)
                {
                    for (; impLvl <= 1; impLvl += 0.001) //impLvl ∈ (0.5, 1.0)
                    {
                        if (BeliefUpdater.updateFunc(thought.PriorBelief, 1 - impLvl, l) < sigmaLeft)
                        {
                            //重要視度を決定
                            Candidate newcan = new Candidate(-l, impLvl);

                            //この重要視度で、逆側に行くときは、何ステップでいけるのか?
                            double tmpBelief = thought.PriorBelief;
                            int    count     = 0;
                            do
                            {
                                tmpBelief = BeliefUpdater.updateFunc(tmpBelief, impLvl); //1-impLvlの逆なのでimpLvl
                                count++;
                            } while (!(tmpBelief >= sigmaRight));                        //0.8を超えたら

                            newcan.OtherJumpNum = count;


                            candidates[l - 1 + dn] = newcan;

                            break;
                        }
                    }
                }
            }//lock
            CurrentCandidate = candidates.Last();

            OnEstimationChanged(new EstimationEventArgs(Candidates));

            OnCandidateChanged(new CandidateEventArgs(CurrentCandidate));
        }
Пример #12
0
 public EnterBuildingAction(IThought initiatingThought, IBuilding building)
     : base(initiatingThought, ActionType.EnterBuilding, new Percent(_defaultPriority))
 {
     BuildingToEnter = building;
 }
        //候補集合を初期化
        public void BuildCandidate(int neighbourNum, IThought thought)//ご近所の数と初期重要視度を渡されることで候補を生成
        {
            if (neighbourNum <= 0)
            {
                return;
            }

            //Sigma=Thought   PriorBelief=Thought   updateFunc=BeliefUpdater
            lock (CandidateLock)
            {
                //ご近所の数
                int dn = neighbourNum;

                //ご近所の数の2倍だけ作成
                candidates = new Candidate[2 * dn];

                double sigmaRight = thought.SigmaRight;
                double sigmaLeft = thought.SigmaLeft;

                double impLvl = 0.5;
                // Jumpnum = 3, 2, 1と調べていく.
                for (int l = dn; l >= 0; l--)
                {
                    //importance levelを上げていって,beliefがしきい値を超えたときその値を使う.
                    for (; impLvl <= 1; impLvl += 0.001)
                    {
                        if (BeliefUpdater.updateFunc(thought.PriorBelief, impLvl, l) > sigmaRight)
                        {
                            Candidate newcan = new Candidate(l, impLvl);

                            //この重要視度で、逆側に行くときは、何ステップでいけるのか?
                            double tmpBelief = thought.PriorBelief;
                            int count = 0;
                            do
                            {
                                tmpBelief = BeliefUpdater.updateFunc(tmpBelief, 1 - impLvl);//逆では1-impLvl
                                count++;

                            } while (!(tmpBelief <= sigmaLeft));

                            newcan.OtherJumpNum = count;

                            candidates[l - 1] = newcan;
                            break;
                        }
                    }
                }

                impLvl = 0.5;
                for (int l = dn; l >= 0; l--)
                {
                    for (; impLvl <= 1; impLvl += 0.001) //impLvl ∈ (0.5, 1.0)
                    {
                        if (BeliefUpdater.updateFunc(thought.PriorBelief, 1 - impLvl,l) < sigmaLeft)
                        {
                            //重要視度を決定
                            Candidate newcan = new Candidate(-l, impLvl);

                            //この重要視度で、逆側に行くときは、何ステップでいけるのか?
                            double tmpBelief = thought.PriorBelief;
                            int count = 0;
                            do
                            {
                                tmpBelief = BeliefUpdater.updateFunc(tmpBelief, impLvl);//1-impLvlの逆なのでimpLvl
                                count++;

                            } while (!(tmpBelief >= sigmaRight));//0.8を超えたら

                            newcan.OtherJumpNum = count;


                            candidates[l - 1 + dn] = newcan;

                            break;
                        }
                    }
                }
            }//lock
            CurrentCandidate = candidates.Last();

            OnEstimationChanged(new EstimationEventArgs(Candidates));

            OnCandidateChanged(new CandidateEventArgs(CurrentCandidate));
        }
Пример #14
0
 public BasicMovementAction(IThought initiatingThought, IBuilding building) : this(initiatingThought, building.Position)
 {
 }
Пример #15
0
 public ActionBase(IThought initiatingThought, ActionType actionType, IPercent priority) : base(actionType.ToString())
 {
     InitiatingThought = initiatingThought;
     ActionType        = actionType;
     Priority          = priority;
 }
Пример #16
0
        //候補集合、初期値を引き継ぐ。
        public override void InheritFrom(AgentAlgorithm otherAlgo)
        {
            if (otherAlgo is IAATBasedAgent)
            {
                AgentSpec spec = (otherAlgo as IAATBasedAgent).publishSpec();

                Thought = new Thought(spec.PriorBelief);
                CandidateSelector = spec.CandidateSelector;

                Body = otherAlgo.Body;
                //候補集合と現在の重要視度だけは引き継ぐ
            }
            else
            {
                throw new Exception(otherAlgo.GetType().Name + "は互換性のない型です。");
            }
        }
Пример #17
0
 public EnemyBrain(ICharacter owner)
 {
     _owner       = owner;
     _idleThought = new IdleThought();
     EnterThought(ThoughtType.Idle);
 }