private Vecteur getPointInformation(Coordonnee pointActuel, Coordonnee pointViser)
        {
            int tempX = pointViser.x;
            int tempY = pointViser.y;

            int ponderationVec = 2;
            int nouveauPointX  = tempX;
            int nouveauPointY  = tempY;

            if (tempX < 0)
            {
                nouveauPointX  = sizeX - 1;
                ponderationVec = 1;
            }

            if (tempY < 0)
            {
                nouveauPointY  = sizeY - 1;
                ponderationVec = 1;
            }

            int maxIndexX = sizeX - 1;

            if (tempX > maxIndexX)
            {
                nouveauPointX  = 0;
                ponderationVec = 1;
            }

            int maxIndexY = sizeY - 1;

            if (tempY > maxIndexY)
            {
                nouveauPointY  = 0;
                ponderationVec = 1;
            }

            Coordonnee coord = new Coordonnee()
            {
                x = nouveauPointX, y = nouveauPointY
            };


            if (isObstacle(coord))
            {
                Vecteur vec = new Vecteur()
                {
                    coor = coord, ponderation = ponderationVec, obstacle = true
                };
                return(vec);
            }
            else
            {
                Vecteur vec = new Vecteur()
                {
                    coor = coord, ponderation = ponderationVec, obstacle = false
                };
                return(vec);
            }
        }
Example #2
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);
        }
 private bool isObstacle(Coordonnee coor)
 {
     if (tabInitial[coor.x, coor.y])
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Example #4
0
        public bool isFinishIsReach(Coordonnee finish)
        {
            bool res = false;

            foreach (Coordonnee coor in listeCoor)
            {
                if (coor.x == finish.x && coor.y == finish.y)
                {
                    res = true;
                    break;
                }
            }
            return(res);
        }
 private void add_vertex(Coordonnee name, Vecteur edges)
 {
     if (!graph.ContainsKey(name))
     {
         graph[name] = new List <Vecteur>()
         {
             edges
         };
     }
     else
     {
         List <Vecteur> listEnCours = graph[name];
         listEnCours.Add(edges);
         graph[name] = listEnCours;
     }
 }
        private IEnumerable <Vecteur> getNoeudAutour(Coordonnee pointActuel)
        {
            Stack <Vecteur> stack = new Stack <Vecteur>();

            Vecteur pointGauche = getPointInformation(pointActuel, new Coordonnee()
            {
                x = pointActuel.x - 1, y = pointActuel.y
            });

            if (!pointGauche.obstacle)
            {
                stack.Push(pointGauche);
            }

            Vecteur pointDroite = getPointInformation(pointActuel, new Coordonnee()
            {
                x = pointActuel.x + 1, y = pointActuel.y
            });

            if (!pointDroite.obstacle)
            {
                stack.Push(pointDroite);
            }

            Vecteur pointHaut = getPointInformation(pointActuel, new Coordonnee()
            {
                x = pointActuel.x, y = pointActuel.y + 1
            });

            if (!pointHaut.obstacle)
            {
                stack.Push(pointHaut);
            }

            Vecteur pointBas = getPointInformation(pointActuel, new Coordonnee()
            {
                x = pointActuel.x, y = pointActuel.y - 1
            });

            if (!pointBas.obstacle)
            {
                stack.Push(pointBas);
            }

            return(stack);
        }
        private void generateGraph()
        {
            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    if (tabInitial[x, y])
                    {
                        Coordonnee pointActuel = new Coordonnee()
                        {
                            x = x, y = y
                        };

                        foreach (Vecteur vec in getNoeudAutour(pointActuel))
                        {
                            add_vertex(pointActuel, vec);
                        }
                    }
                }
            }
        }
        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));
        }
Example #9
0
 public void AddCoordonnee(Coordonnee coor, int ponderation)
 {
     listeCoor.Add(coor);
     totalPonderation += ponderation;
 }