Exemplo n.º 1
0
        private void ChooseAction()
        {
            if (IsEnvironnementEmpty())
            {
                intentions.Enqueue(Action.ATTENDRE);
            }
            else
            {
                Node n;
                if (informe)                 // Exploration informee
                {
                    n = new NodeAStar(null, croyance, posI, posJ, Action.ATTENDRE);
                }
                else                   // Exploration non informee
                {
                    n = new NodeUCS(null, croyance, posI, posJ, Action.ATTENDRE);
                }

                // On recupere la meilleure liste d'action et on la definit comme nos intensions
                List <Action> actions = Exploration(n);
                if (actions != null)
                {
                    for (int i = actions.Count - 1; i >= 0; i--)
                    {
                        intentions.Enqueue(actions[i]);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static List <Node> AStarSearch(Node n)
        {
            // Récupérer tous les neouds réalisables a partir de l'etat actuel
            List <Node> neighbors = new List <Node>();

            // Haut
            if (n.agentPosJ > 0)
            {
                Node newNode = new NodeAStar(n, n.map, n.agentPosI, n.agentPosJ - 1, Action.HAUT);
                neighbors.Add(newNode);
            }

            // Bas
            if (n.agentPosJ < Rules.height - 1)
            {
                Node newNode = new NodeAStar(n, n.map, n.agentPosI, n.agentPosJ + 1, Action.BAS);
                neighbors.Add(newNode);
            }

            // Gauche
            if (n.agentPosI > 0)
            {
                Node newNode = new NodeAStar(n, n.map, n.agentPosI - 1, n.agentPosJ, Action.GAUCHE);
                neighbors.Add(newNode);
            }

            // Droite
            if (n.agentPosI < Rules.width - 1)
            {
                Node newNode = new NodeAStar(n, n.map, n.agentPosI + 1, n.agentPosJ, Action.DROITE);
                neighbors.Add(newNode);
            }

            // Aspirer
            if (n.NodeWithPoussiere(n.agentPosI, n.agentPosJ))
            {
                Node newNode = new NodeAStar(n, n.map, n.agentPosI, n.agentPosJ, Action.ASPIRER);
                neighbors.Add(newNode);
            }

            // Ramasser
            if (n.NodeWithBijou(n.agentPosI, n.agentPosJ))
            {
                Node newNode = new NodeAStar(n, n.map, n.agentPosI, n.agentPosJ, Action.RAMASSER);
                neighbors.Add(newNode);
            }

            return(neighbors);
        }
Exemplo n.º 3
0
        private List <Action> Exploration(Node root)
        {
            List <Node> visited   = new List <Node>();
            List <Node> frontiere = new List <Node> {
                root
            };

            while (true)
            {
                if (frontiere.Count == 0)
                {
                    return(null);
                }

                Node n = frontiere[0];
                frontiere.RemoveAt(0);
                // On ne reexplore pas les noeuds deja visites
                while (visited.Contains(n))
                {
                    n = frontiere[0];
                    frontiere.RemoveAt(0);
                }

                visited.Add(n);


                // Si n est solution
                if (n.cost < desir)
                {
                    // On recupere la liste d'action en remontant la branche de l'arbre de decision
                    List <Action> actions = new List <Action>();
                    Node          current = n;
                    while (current != null)
                    {
                        actions.Add(current.action);
                        current = current.parent;
                    }
                    return(actions);
                }

                // Expansion
                if (n.depth < Rules.maxSearchDepth)
                {
                    if (informe)
                    {
                        // Exploration AStar
                        frontiere.AddRange(NodeAStar.AStarSearch(n));
                        // Tri des noeuds par cout croissant
                        frontiere.Sort((x, y) => x.Eval().CompareTo(y.Eval()));
                    }
                    else
                    {
                        // Exploration Uniform Cost Search (UCS)
                        frontiere.AddRange(NodeUCS.UCSearch(n));
                        // Tri des noeuds par cout croissant
                        frontiere.Sort((x, y) => x.Eval().CompareTo(y.Eval()));
                    }
                }
                else
                {
                    return(null);
                }
            }
        }