예제 #1
0
    public TerrainStructure(StoryStructure storyStructure, List <BiomeSettings> availableBiomes, float mapSize,
                            int heightMapResolution, int octaves,
                            int voronoiSamples, int lloydIterations, float heightNoise, float alphaNoise, float borderBlockerBlockerOffset)
    {
        AreaSegmentGraph   = new GrammarGraph <AreaSegment>();
        BorderBlockerLines = new List <Vector2[]>();
        AreaBlockerLines   = new List <Vector2[]>();
        MainPathLines      = new List <Vector2[]>();
        SidePathLines      = new List <Vector2[]>();
        PathPolygons       = new List <Vector2[]>();

        var filteredBiomes = availableBiomes;

        // Select a random biome out of the available ones for the current level
        if (GameController.Instance && availableBiomes.Count > 1)
        {
            filteredBiomes = availableBiomes.Where(biome => GameController.Instance.LastPlayedBiome != biome.UniqueName).ToList();
        }
        BiomeSettings = filteredBiomes[Random.Range(0, filteredBiomes.Count)];
        if (GameController.Instance)
        {
            GameController.Instance.LastPlayedBiome = BiomeSettings.UniqueName;
        }

        MapSize             = mapSize;
        HeightMapResolution = heightMapResolution;
        Octaves             = octaves;

        BorderSettings   = BiomeSettings.BorderBiome;
        _lloydIterations = lloydIterations;
        _voronoiSamples  = voronoiSamples;
        _heightNoise     = heightNoise;
        _alphaNoise      = alphaNoise;

        // Add splat prototypes to the shader
        CreateShaderTextures();

        // Create base graph that later on is transformed with a set of rules and assigned areas to
        CreateBaseGraph(lloydIterations);

        // Assign specific areas to each node of the base graph - Start point, Boss arena, paths...
        CreateAreaGraph(storyStructure.Rewrites);
        var startID = AreaSegmentGraph.FindNodesWithData(new AreaSegment(AreaSegment.EAreaSegmentType.Start))[0];

        Start = new KeyValuePair <Vector2, int>(_areaSegmentCenterMap[startID], startID);


        // Populate area segment blockers list
        CreateAreaBlockerLines();

        // Populate border lines list
        CreateBorderBlockerLines(borderBlockerBlockerOffset);

        // Populate path lines list
        CreatePathLines();

        // Create path polygons
        CreatePathPolygons(BiomeSettings.PathHalfWidth);
    }
예제 #2
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            try
            {
                InputGrammar = Grammar.Parse(tbInputGrammar.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Wrong input: " + exception.Message);
            }

            tbResult.Clear();

            var splittingSymbols = tbSplittingSymbols.Text.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

            var processedGrammar = InputGrammar.Clone();

            processedGrammar.NonterminalSymbols = InputGrammar.NonterminalSymbols
                                                  .Except(splittingSymbols).ToList();

            processedGrammar.TerminalSymbols = InputGrammar.TerminalSymbols
                                               .Union(splittingSymbols.Select(symbol => symbol + Helper.NewStartSymbolSuffix)).ToList();

            foreach (var rule in processedGrammar.Rules)
            {
                foreach (var word in rule.RightPartArray)
                {
                    foreach (var splitSymbol in splittingSymbols)
                    {
                        for (int i = 0; i < word.Count; i++)
                        {
                            word[i] = word[i].Replace(splitSymbol, splitSymbol + Helper.NewStartSymbolSuffix);
                        }
                    }
                }
            }

            Grammar[] resultGrammars = new Grammar[splittingSymbols.Length];

            for (int i = 0; i < splittingSymbols.Length; i++)
            {
                resultGrammars[i] = processedGrammar.Clone();

                resultGrammars[i].NonterminalSymbols.Add(splittingSymbols[i]);

                resultGrammars[i].StartSymbol = splittingSymbols[i];

                var grammarGraph = new GrammarGraph(resultGrammars[i]);
                grammarGraph.RemoveUselessSymbols();
                grammarGraph.RemoveUnreachableSymbols();


                resultGrammars[i] = grammarGraph.Grammar;

                tbResult.Text += resultGrammars[i].ToString() + Environment.NewLine + Environment.NewLine;
            }
        }
예제 #3
0
    public SceneryStructure(StoryStructure storyStructure, TerrainStructure terrainStructure)
    {
        _graph = new GrammarGraph <AreaSegment>(terrainStructure.AreaSegmentGraph);

        // Assign speacial areas
        CreateSpecialAreas(terrainStructure);

        // Assign paths to area settings
        CreatePathAreas(terrainStructure);

        // Assign boss area segments to area settings
        CreateBossAreas(terrainStructure);
    }
예제 #4
0
        private void btnSolve_Click(object sender, EventArgs e)
        {
            try
            {
                Grammar = Grammar.Parse(tbInputGrammar.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Wrong input: " + exception.Message);
            }

            try
            {
                var graph = new GrammarGraph(Grammar);

                /*
                 * graph.RemoveEmptyRightPartRools();
                 * graph.RemoveUselessSymbols();
                 * graph.RemoveUnreachableSymbols();*/

                tbOutputGrammar.Text = graph.Grammar.ToString();

                SRE = new SystemOfRegularEquations(graph.Grammar);

                tbCoefficients.Text = SRE.ToString();

                tbSolution.Text = string.Empty;
                var result = SRE.Solve();
                for (int i = 0; i < result.Length; i++)
                {
                    tbSolution.Text += String.Format("{0}{1} = {2}{3}", Helper.VarName, i + 1, result[i].Symbol, Environment.NewLine);
                }

                finiteStateMachine = new FiniteStateMachine(result[0].Symbol);

                var nda = new Graph("NDA");
                foreach (var node in finiteStateMachine.Nodes)
                {
                    foreach (var children in node.ChildrenNodes)
                    {
                        var edge = nda.AddEdge("S" + (node.Number + 1).ToString(),
                                               "S" + (children.Value.Number + 1).ToString());
                        edge.Attr.Id = children.Key;
                    }
                }

                nda.FindNode("S1").Attr.FillColor = Color.MediumSeaGreen;

                foreach (var node in finiteStateMachine.LastNodes)
                {
                    nda.FindNode("S" + (node.Number + 1)).Attr.FillColor = new Color(0xFF, 0xFF, 0x99);
                }

                ndaViewer.Graph = nda;

                lblAnswer.Visible = false;
            }
            catch (Exception exception)
            {
                MessageBox.Show("Incorrect input grammar: " + exception.Message);
            }
        }
예제 #5
0
 public GrammarGraph(GrammarGraph <T> original)
 {
     Nodes       = (from x in original.Nodes select x).ToDictionary(x => x.Key, x => x.Value.Clone());
     Edges       = (from x in original.Edges select x).ToDictionary(x => x.Key, x => x.Value);
     NodeIDCount = original.NodeIDCount;
 }