Example #1
0
 static bool Contains(NoeudStar n, List<NoeudStar> list)
 {
     foreach (NoeudStar c in list)
         if (c.position == n.position)
             return true;
     return false;
 }
Example #2
0
 static List<NoeudStar> buildChemin(NoeudStar current)
 {
     List<NoeudStar> chemin = new List<NoeudStar> { };
     while (current != null)
     {
         chemin.Add(current);
         current = current.parent;
     }
     chemin.Reverse();
     return chemin;
 }
Example #3
0
        public static List<NoeudStar> getVoisins(NoeudStar n, NoeudStar[,] map)
        {
            List<NoeudStar> result = new List<NoeudStar> { };
            if (n.position.X != 0 && map[n.position.X - 1, n.position.Y].walkable)
                result.Add(map[n.position.X - 1, n.position.Y]);
            if (n.position.X != Map.tailleX - 1 && map[n.position.X + 1, n.position.Y].walkable)
                result.Add(map[n.position.X + 1, n.position.Y]);
            if (n.position.Y != Map.tailleY - 1 && map[n.position.X, n.position.Y + 1].walkable)
                result.Add(map[n.position.X, n.position.Y + 1]);
            if (n.position.Y != 0 && map[n.position.X, n.position.Y - 1].walkable)
                result.Add(map[n.position.X, n.position.Y - 1]);

            return result;
        }
Example #4
0
 static NoeudStar[,] Init(Point depart, Point arrivee)
 {
     NoeudStar[,] map = new NoeudStar[Map.tailleX, Map.tailleY];
     for (int i = 0; i < Map.tailleX; i++)
         for (int j = 0; j < Map.tailleY; j++)
         {
             map[i, j] = new NoeudStar(new Point(i, j));
             if (Map.tuiles[i, j].value != 0)
                 map[i, j].walkable = true;
         }
     foreach (Unite u in Map.unites)
     {
         map[(int)u.position.X, (int)u.position.Y].walkable = false;
         if(u.position.X - (int)u.position.X != 0)
             map[(int)u.position.X + 1, (int)u.position.Y].walkable = false;
         if (u.position.Y - (int)u.position.Y != 0)
             map[(int)u.position.X, (int)u.position.Y + 1].walkable = false;
     }
     return map;
 }