예제 #1
0
        public List <Chemin> exploreNewChemin(Dictionary <Coordonnee, List <Vecteur> > graph)
        {
            int lastindex = listeCoor.Count - 1;

            Coordonnee     temp         = listeCoor[lastindex];
            List <Vecteur> pointsAutour = graph[temp];

            List <Chemin> resChemin = new List <Chemin>();

            foreach (Vecteur vec in pointsAutour)
            {
                if (!listeCoor.Contains(vec.coor)) // Si cette coordonnée ne fait pas partie du chemin actuel
                {
                    Chemin chem = new Chemin();
                    foreach (Coordonnee coordo in listeCoor)
                    {
                        chem.AddCoordonnee(new Coordonnee {
                            x = coordo.x, y = coordo.y
                        }, 0);
                    }
                    chem.totalPonderation = this.totalPonderation;

                    chem.AddCoordonnee(vec.coor, vec.ponderation);
                    resChemin.Add(chem);
                }
            }

            return(resChemin);
        }
예제 #2
0
        /*
         *
         * private void deplacerRobot(int[] nextPositionRobot)
         * {
         *  // Si il n'y a pas d'obstacle, alors on execute l'action de deplacement
         *  if (!isObstacle(this.currentPosition, nextPositionRobot))
         *  {
         *      this.previousPosition = this.currentPosition;
         *      this.currentPosition = nextPosition;
         *
         *      // Faire le déplacement ici ...
         *
         *  }
         *  else
         *  {
         *      Console.WriteLine("Impossible d'éffectuer le déplamecement car un obstacle est présent !");
         *  }
         * }
         *
         * private int[] getDirectionRobot(Node currentPosition, Node previousPosition)
         * {
         *  int[] direction = new int[2];
         *  int x = 0, y = 0;
         *
         *  // Si x =  1; --> Le devant du robot vise la DROITE     // Si y =  1; --> Le devant du robot vise la HAUT
         *  // Si x = -1; --> Le devant du robot vise la GAUCHE     // Si y = -1; --> Le devant du robot vise la BAS
         *  if (currentPosition[0] > previousPosition[0])
         *  {
         *      x = 1;
         *      Console.WriteLine("Va vers DROITE");
         *  }
         *  else
         *  {
         *      x = -1;
         *      Console.WriteLine("Va vers GAUCHE");
         *  }
         *
         *  if (currentPosition[1] > previousPosition[1])
         *  {
         *      y = 1;
         *      Console.WriteLine("Va vers le HAUT");
         *  }
         *  else
         *  {
         *      y = -1;
         *      Console.WriteLine("Va vers le BAS");
         *  }
         *
         *  direction.SetValue(x, 0);
         *  direction.SetValue(y, 1);
         *
         *  return direction;
         * }
         *
         * private int[] nextPositionAvancer(int[] currentPosition, int[] previousPosition)
         * {
         *  int[] nextPosition = new int[2];
         *  int[] dir = getDirectionRobot(currentPosition, previousPosition);
         *  int nextX = 0, nextY = 0;
         *
         *  if (dir[0] == 0 && dir[1] == 0)
         *  {
         *      nextY = currentPosition[1] + 1;
         *      nextPosition.SetValue(nextY, 1);
         *  }
         *  else
         *  {
         *      if (dir[0] > 0) // Vers la droite
         *      {
         *          nextX = currentPosition[0] + 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *      else
         *      {
         *          nextX = currentPosition[0] - 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *
         *      if (dir[1] > 0) // Vers le haut
         *      {
         *          nextY = currentPosition[1] + 1;
         *          nextPosition.SetValue(nextY, 1);
         *      }
         *      else
         *      {
         *          nextY = currentPosition[1] - 1;
         *          nextPosition.SetValue(nextY, 1);
         *      }
         *  }
         *
         *
         *
         *  return nextPosition;
         * }
         *
         * private int[] nextPositionReculer(int[] currentPosition, int[] previousPosition)
         * {
         *  int[] nextPosition = new int[2];
         *  int[] dir = getDirectionRobot(currentPosition, previousPosition);
         *  int nextX = 0, nextY = 0;
         *
         *  if (dir[0] == 0 && dir[1] == 0)
         *  {
         *      nextY = currentPosition[1] - 1;
         *      nextPosition.SetValue(nextY, 1);
         *  }
         *  else
         *  {
         *      if (dir[0] > 0) // Vers la droite
         *      {
         *          nextX = currentPosition[0] - 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *      else
         *      {
         *          nextX = currentPosition[0] + 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *
         *      if (dir[1] > 0) // Vers le haut
         *      {
         *          nextY = currentPosition[1] - 1;
         *          nextPosition.SetValue(nextY, 1);
         *      }
         *      else
         *      {
         *          nextY = currentPosition[1] + 1;
         *          nextPosition.SetValue(nextY, 1);
         *      }
         *  }
         *
         *
         *
         *
         *  return nextPosition;
         * }
         *
         * private int[] nextPositionDroite(int[] currentPosition, int[] previousPosition)
         * {
         *  int[] nextPosition = new int[2];
         *  int[] dir = getDirectionRobot(currentPosition, previousPosition);
         *  int nextX = 0, nextY = 0;
         *
         *  if (dir[0] == 0 && dir[1] == 0)
         *  {
         *      nextX = currentPosition[0] + 1;
         *      nextPosition.SetValue(nextX, 0);
         *  }
         *  else
         *  {
         *      if (dir[0] > 0) // Vers la droite
         *      {
         *          nextY = currentPosition[0] - 1;
         *          nextPosition.SetValue(nextY, 1);
         *      }
         *      else
         *      {
         *          nextY = currentPosition[0] + 1;
         *          nextPosition.SetValue(nextX, 1);
         *      }
         *
         *      if (dir[1] > 0) // Vers le haut
         *      {
         *          nextX = currentPosition[1] + 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *      else
         *      {
         *          nextX = currentPosition[1] - 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *  }
         *
         *
         *
         *  return nextPosition;
         * }
         *
         * private int[] nextPositionGauche(int[] currentPosition, int[] previousPosition)
         * {
         *  int[] nextPosition = new int[2];
         *  int[] dir = getDirectionRobot(currentPosition, previousPosition);
         *  int nextX = 0, nextY = 0;
         *
         *  if (dir[0] == 0 && dir[1] == 0)
         *  {
         *      nextX = currentPosition[0] - 1;
         *      nextPosition.SetValue(nextX, 0);
         *  }
         *  else
         *  {
         *      if (dir[0] > 0) // Vers la droite
         *      {
         *          nextY = currentPosition[0] + 1;
         *          nextPosition.SetValue(nextY, 1);
         *      }
         *      else
         *      {
         *          nextY = currentPosition[0] - 1;
         *          nextPosition.SetValue(nextX, 1);
         *      }
         *
         *      if (dir[1] > 0) // Vers le haut
         *      {
         *          nextX = currentPosition[1] - 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *      else
         *      {
         *          nextX = currentPosition[1] + 1;
         *          nextPosition.SetValue(nextX, 0);
         *      }
         *  }
         *
         *
         *  return nextPosition;
         * }
         */

        public void moveTo(int xDestination, int yDestination)
        {
            if ((xDestination < carte.Width - 1) || (yDestination < carte.Height - 1))
            {
                throw new ArgumentOutOfRangeException();
            }
            else
            {
                if (carte.isEmpty(xDestination, yDestination))
                {
                    Node positionRoverDepart  = this.carte.getRover();
                    Node positionRoverArrivee = this.carte.Coordonnees.getCoordonnee(xDestination, yDestination);
                    Dictionary <Node, List <Node> > listVertex = this.graph.generateGraph();

                    Dijkstra shortestPath = new Dijkstra();
                    Chemin   chem         = shortestPath.Chemin_Le_Plus_Cours(positionRoverDepart, positionRoverArrivee, listVertex);

                    foreach (Node c in chem.listeCoor)
                    {
                        Console.WriteLine("Path : [{0}, {1}]", c.x, c.y);
                    }
                }
                else
                {
                    Console.WriteLine("\n\n");
                    throw new CaseIsNotEmptyException();
                }
            }
        }
예제 #3
0
        public Chemin Chemin_Le_Plus_Cours(Coordonnee start, Coordonnee finish, Dictionary <Coordonnee, List <Vecteur> > graph)
        {
            // pour un point donné (A)
            // while
            // liste les noeuds connectés -> création d'un nouveau chemin
            // je prends le chemin le plus court dans la liste créee
            // pour le chemin en cours = remplace A

            List <Chemin> listeDeChemin = new List <Chemin>();

            initialChemin = new Chemin();
            initialChemin.AddCoordonnee(start, 0);
            listeDeChemin.Add(initialChemin);

            List <Chemin> resultat = new List <Chemin>();

            for (int i = 0; i < listeDeChemin.Count; i++)
            {
                Chemin chem = listeDeChemin[i];



                if (chem.isFinishIsReach(finish))
                {
                    resultat.Add(chem);
                    break;
                }


                List <Chemin> newchemins = chem.exploreNewChemin(graph);

                foreach (Chemin newchem in newchemins)
                {
                    listeDeChemin.Add(newchem);
                }
            }


            return(GetMinimalCheminValue(resultat));
        }
예제 #4
0
        public List <Chemin> exploreNewChemin(Dictionary <Node, List <Node> > graph)
        {
            int lastindex = listeCoor.Count - 1;

            Node        temp         = listeCoor[lastindex];
            List <Node> pointsAutour = graph[temp];

            List <Chemin> resChemin = new List <Chemin>();

            foreach (Node vec in pointsAutour)
            {
                if (!listeCoor.Contains(vec)) // Si cette coordonnée ne fait pas partie du chemin actuel
                {
                    Chemin chem = new Chemin();
                    foreach (Node coordo in listeCoor)
                    {
                        try
                        {
                            chem.AddCoordonnee(new Node()
                            {
                                x = coordo.x, y = coordo.y, ponderation = coordo.ponderation
                            }, 0);
                        }
                        catch (OutOfMemoryException e)
                        {
                            Console.WriteLine("Exception : La grille est trop complexe. Celle-ci demande un calcul trop important en mémoire. Veuillez réduire sa taille, ou réduire le nombre d'obstacle." + e.Message);
                        }
                    }
                    chem.totalPonderation = this.totalPonderation;

                    chem.AddCoordonnee(vec, vec.ponderation);
                    resChemin.Add(chem);
                }
            }

            return(resChemin);
        }