Esempio n. 1
0
        // Done!
        #region Methods

        private bool Search()
        {
            PriorityQueue <CognitiveState <T> >    open   = new PriorityQueue <CognitiveState <T> >();
            IDictionary <int, CognitiveState <T> > closed = new Dictionary <int, CognitiveState <T> >(500);

            // Reinicializar as variáveis
            result = null;

            // Vamos começar a expandir a partir deste estado!
            open.Enqueue(0, start);

            while (open.Count > 0)
            {
                // Apanhar o "melhor" estado possivel!
                CognitiveState <T> node = open.Dequeue();

                // Adicionar à lista de fechados! <<extension>>
                closed.Add(node);

                // Verificar se chegamos à solução!
                if (node.IsGoal(goal))
                {
                    result = node;
                    return(true);
                }

                // Adicionar filhos à lista de abertos!
                // Depois de os filtramos é claro!
                open.FilterAdd(closed, node, goal, this.agentCharacter);
            }

            return(false);
        }
Esempio n. 2
0
        private bool SearchAStar(PriorityQueue <CognitiveState <T> > open, PriorityQueue <CognitiveState <T> > frontier)
        {
            IDictionary <int, CognitiveState <T> > closed = new Dictionary <int, CognitiveState <T> >(500);

            while (open.Count > 0)
            {
                // Apanhar o "melhor" estado possivel!
                CognitiveState <T> node = open.Dequeue();

                // Adicionar à lista de fechados! <<extension>>
                ((ICollection <CognitiveState <T> >)closed).Add(node);

                // Verificar se chegamos à solução!
                if (node.IsGoal(goal))
                {
                    result = node;
                    return(true);
                }

                // Adicionar filhos à lista de abertos!
                // Depois de os filtramos é claro!
                open.FilterAdd(closed, node, goal, this.agentCharacter);
            }

            cutOff += (int)Math.Ceiling(frontier.Peek().Layout.GetHeuristic(frontier.Peek().Layout, goal.Layout));

            return(false);
        }