示例#1
0
        public ICollection <IWeightedGraphNode <T> > GetWeightedGraphNodes()
        {
            List <IWeightedGraphNode <T> > result = new List <IWeightedGraphNode <T> >(Count);

            for (int i = 0; i < Count; i++)
            {
                WeightedGraphNode <T> node = new WeightedGraphNode <T>(InfinityWeight);
                int y = i / Width;
                int x = i - y * Width;
                node.Position = new Vector2Int(x, y);
                result.Add(node);
            }

            for (int i = 0; i < Count; i++)
            {
                WeightedGraphNode <T> node = (WeightedGraphNode <T>)result[i];

                for (int j = 0; j < Count; j++)
                {
                    WeightedGraphNode <T> connection = (WeightedGraphNode <T>)result[i];
                    node.Add(connection);
                    node.SetWeight(node.Count - 1, _weights[i, j]);
                }
            }

            return(result);
        }