loadGraph() public method

load a graph from a txt file that is formated in a certain way
public loadGraph ( string filename ) : void
filename string the file path
return void
Esempio n. 1
0
        /// <summary>
        /// Generate the mission graph and return it
        /// </summary>
        /// <param name="startname">the starting graph which is usually a start and exist</param>
        /// <param name="recipename">the recipe file that need to be exectuted to generate the graph</param>
        /// <param name="maxConnections">the maximum number of connection any node should have (4 is the default to help the layout generation)</param>
        /// <returns>the generated mission graph</returns>
        public Graph GenerateDungeon(string startname, string recipename, int maxConnections = 4)
        {
            Graph graph = new Graph();

            graph.loadGraph(startname);

            List <Recipe> recipes = Recipe.loadRecipes(recipename);

            foreach (Recipe r in recipes)
            {
                if (this.patterns.ContainsKey(r.action.ToLower()))
                {
                    int count = this.random.Next(r.maxTimes - r.minTimes + 1) + r.minTimes;
                    for (int i = 0; i < count; i++)
                    {
                        this.patterns[r.action.ToLower()].applyPattern(graph, maxConnections);
                    }
                }
                else
                {
                    Pattern randomPattern = null;
                    foreach (Pattern p in this.patterns.Values)
                    {
                        if (randomPattern == null || this.random.NextDouble() < 0.3)
                        {
                            randomPattern = p;
                        }
                    }
                    randomPattern.applyPattern(graph, maxConnections);
                }
            }
            return(graph);
        }
Esempio n. 2
0
        /// <summary>
        /// Load the pattern folder where input.txt is the graph to be matched
        /// and output files are all applicable results
        /// </summary>
        /// <param name="foldername">the folder path for the pattern matching</param>
        public void loadPattern(string foldername)
        {
            this.patternMatch = new Graph();
            this.patternMatch.loadGraph(foldername + "input.txt");

            this.patternApply = new List <Graph>();
            string[] files = Directory.GetFiles(foldername, "output*");
            foreach (string f in files)
            {
                Graph temp = new Graph();
                temp.loadGraph(f);
                this.patternApply.Add(temp);
            }
        }