Пример #1
0
 private static Node[,] CreerTable(int tx, int ty)
 {
     Node[,] t = new Node[tx, ty];
     for (int i = 0; i < tx; i++)
     {
         for (int j = 0; j < ty; j++)
         {
             Node temp = new Node(i, j);
             t[i, j] = temp;
         }
     }
     return t;
 }
Пример #2
0
 public int SimulateCalculerG(Node parent, int horizontal, int diagonal)
 {
     if (parent != null)
     {
         Node temp;
         var g = this.pos.DifferenceSurDeuxAxes(parent.pos) ? diagonal : horizontal; // si diagonale : 140 au depart
         temp = parent;
         g += temp.G;
         while (temp.Parent != null)
         {
             temp = temp.Parent;
             g += temp.G;
         }
         return g;
     }
     return -1;
 }
Пример #3
0
 private Node[,] PreparerTableau(int[,] tab)
 {
     int t1 = tab.GetLength(0);
     int t2 = tab.GetLength(1);
     var temp = new Node[t1, t2];
     for (int x = 0; x < t1; x++)
     {
         for (int j = 0; j < t2; j++)
         {
             temp[x, j] = new Node(x, j, tab[x, j] == 9);
         }
     }
     return temp;
 }
Пример #4
0
        public List<Node> GetAdjacents(Coordonnees c, Node[,] table)
        {
            List<Node> list = new List<Node>();
            bool flagXMin = c.X > 0;
            bool flagXMax = c.X < table.GetLength(0) - 1;
            bool flagYMin = c.Y > 0;
            bool flagYMax = c.Y < table.GetLength(1) - 1;
            var flagDiagoOk = this.diag < 2*this.vertical;
            //if (flagXMin)
            //{
            //    if (flagYMin)
            //        list.Add(table[c.X - 1, c.Y - 1]);
            //    list.Add(table[c.X - 1, c.Y]);
            //    if (flagYMax)
            //        list.Add(table[c.X - 1, c.Y + 1]);

            //}

            //if (flagXMax)
            //{
            //    if (flagYMin)
            //        list.Add(table[c.X + 1, c.Y - 1]);
            //    list.Add(table[c.X + 1, c.Y]);
            //    if (flagYMax)
            //        list.Add(table[c.X + 1, c.Y + 1]);

            //}

            //if (flagYMin)
            //    list.Add(table[c.X, c.Y - 1]);
            //if (flagYMax)
            //    list.Add(table[c.X, c.Y + 1]);
            if (flagXMin)
                list.Add(table[c.X - 1, c.Y]);
            if (flagXMax)
                list.Add(table[c.X + 1, c.Y]);

            if (flagYMin)
                list.Add(table[c.X, c.Y - 1]);
            if (flagYMax)
                list.Add(table[c.X, c.Y + 1]);

            var flagUseDiago = list.Where(x => !x.Obstacle).Count() < 2; //necessité utiliser diago pour avancer
            if(flagDiagoOk || (flagUseDiago)) //si les diago sont ok pour utiliser ou si on a pas le choix
            {
                if(flagXMin&&flagYMin)
                    list.Add(table[c.X - 1, c.Y - 1]);
                if(flagXMin&&flagYMax)
                    list.Add(table[c.X - 1, c.Y + 1]);

                if(flagXMax&&flagYMin)
                    list.Add(table[c.X + 1, c.Y - 1]);
                if(flagXMax&&flagYMax)
                    list.Add(table[c.X + 1, c.Y + 1]);
            }

            return list;
        }