Exemplo n.º 1
0
        private static List <RecipeNode> InitRecipes(string fileName)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(Path.GetFullPath(Path.Combine(Application.StartupPath, $@"..\..\{fileName}.xml")));

            var recipes = new List <Recipee>();

            foreach (XmlNode node in doc.SelectNodes("//recipe"))
            {
                var r = new Recipee();
                r.Name = node.Attributes["name"]?.Value;
                foreach (XmlNode child in node.ChildNodes)
                {
                    var m = new ResourceChunk()
                    {
                        Name     = child.Attributes["name"].Value,
                        Quantity = decimal.Parse(child.Attributes["q"].Value.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator))
                    };

                    if (child.Name == "input")
                    {
                        r.Inputs.Add(m);
                    }
                    else
                    {
                        r.Outputs.Add(m);
                    }
                }

                recipes.Add(r);
            }



            List <RecipeNode> labels = new List <RecipeNode>();

            foreach (Recipee rec in recipes)
            {
                var r = new RecipeNode()
                {
                    Recipe = rec
                };
                labels.Add(r);
            }



            foreach (var item in labels)
            {
                foreach (var input in item.Recipe.Inputs)
                {
                    foreach (var matchedRecipeLabel in labels.Where(_ => _.Recipe.Outputs.Any(__ => __.Name == input.Name)))
                    {
                        item.IncomingRecipes.Add(matchedRecipeLabel);
                    }
                }

                foreach (var output in item.Recipe.Outputs)
                {
                    foreach (var matchedRecipeLabel in labels.Where(_ => _.Recipe.Inputs.Any(__ => __.Name == output.Name)))
                    {
                        item.OutGoingRecipes.Add(matchedRecipeLabel);
                    }
                }
            }

            return(labels);
        }
Exemplo n.º 2
0
        private void be()
        {
            Class1.Start();
            return;

            var root = JsonConvert.DeserializeObject <Root>(File.ReadAllText(@"C:\Users\tmi\Downloads\f.txt"));
            //var root = JsonConvert.DeserializeObject<Root>(File.ReadAllText(@"C:\Downloads\f.txt"));
            List <Recipee> rec = new List <Recipee>();

            foreach (Recipe node in root.recipes)
            {
                var r = new Recipee();
                if (
                    node.name.IndexOf("void") >= 0 ||
                    node.name.IndexOf("crate") >= 0 ||
                    node.name.IndexOf("stack") >= 0 ||
                    node.name.IndexOf("barrel") >= 0 ||
                    node.name.IndexOf("delivery") >= 0 ||
                    node.name.IndexOf("pack") >= 0 ||
                    node.name.IndexOf("blackhole") >= 0
                    )
                {
                    continue;
                }
                r.Name = node.name;
                foreach (Ingredient child in node.ingredients)
                {
                    var m = new ResourceChunk()
                    {
                        Name     = child.name,
                        Quantity = child.amount,
                    };

                    r.Inputs.Add(m);
                }

                foreach (Product child in node.products)
                {
                    var m = new ResourceChunk()
                    {
                        Name        = child.name,
                        Quantity    = child.amount,
                        Probability = child.probability
                    };

                    r.Outputs.Add(m);
                }
                rec.Add(r);
            }

            List <RecipeNode> labels = new List <RecipeNode>();

            foreach (Recipee re in rec)
            {
                var r = new RecipeNode()
                {
                    Recipe = re
                };
                labels.Add(r);
            }



            labels = getMostEfficientPath(labels, "titanium", "ore-titanium", "titanium-plate", 1000);
            //labels = getMostEfficientPath(labels);
        }