예제 #1
0
        private static Previous ProcessBridges(Inventory inventory)
        {
            var queue    = new Queue <Bridge>();
            var previous = new Previous();

            foreach (var cmp in inventory.LinkLookup[0])
            {
                var bridge = new Bridge()
                {
                    Parts = new List <Component>()
                };
                bridge.Parts.Add(cmp);
                queue.Enqueue(bridge);
            }
            while (queue.Any())
            {
                var bridge = queue.Dequeue();
                previous.AddBridge(bridge);
                var nextLink  = bridge.GetNextLink();
                var possibles = inventory.LinkLookup.GetValueOrDefault(nextLink);
                if (possibles == null)
                {
                    continue;
                }
                foreach (var possible in possibles)
                {
                    if (bridge.Parts.Contains(possible))
                    {
                        continue;
                    }
                    var newBridge = new Bridge()
                    {
                        Parts = new List <Component>(bridge.Parts)
                    };
                    newBridge.Parts.Add(possible);
                    queue.Enqueue(newBridge);
                }
            }

            return(previous);
        }