Exemplo n.º 1
0
 public Grid2D(int width, int height)
 {
     nodes = new Node2D[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             nodes[i, j] = new Node2D(this, i, j);
         }
     }
 }
Exemplo n.º 2
0
        void CreateConnectionIfValid(List<NodeConnection> list, Node2D nodeFrom, Node2D nodeTo)
        {
            if (nodeTo.Weight < Single.MaxValue)
            {
                var conn = new NodeConnection {
                    // 1.4 for diagonals and 1 for horizontal or vertical connections
                    Cost = nodeFrom.X == nodeTo.X || nodeFrom.Y == nodeTo.Y ? 1 : 1.4f,
                    From = nodeFrom,
                    To = nodeTo,
                };

                list.Add(conn);
            }
        }