コード例 #1
0
    private void GenerateNGram()
    {
        if (blackBoard.ConfigUI.Config.HeiarchalEnabled)
        {
            grammar = NGramFactory.InitHierarchicalNGram(
                blackBoard.ConfigUI.Config.N,
                blackBoard.ConfigUI.Config.HeiarchalMemory);

            simpleGrammar = NGramFactory.InitHierarchicalNGram(
                blackBoard.ConfigUI.Config.N,
                blackBoard.ConfigUI.Config.HeiarchalMemory);
        }
        else if (blackBoard.ConfigUI.Config.BackOffEnabled)
        {
            grammar = NGramFactory.InitHierarchicalNGram(
                blackBoard.ConfigUI.Config.N,
                blackBoard.ConfigUI.Config.BackOffMemory);

            simpleGrammar = NGramFactory.InitHierarchicalNGram(
                blackBoard.ConfigUI.Config.N,
                blackBoard.ConfigUI.Config.BackOffMemory);
        }
        else
        {
            grammar       = NGramFactory.InitGrammar(blackBoard.ConfigUI.Config.N);
            simpleGrammar = NGramFactory.InitGrammar(blackBoard.ConfigUI.Config.N);
        }

        for (int i = 0; i <= blackBoard.ProgressIndex; ++i)
        {
            if (blackBoard.ConfigUI.Config.UsingTieredGeneration || blackBoard.ProgressIndex == i)
            {
                JsonObject tierInfo   = blackBoard.GameFlow[i].AsJsonObject;
                JsonArray  tierLevels = tierInfo[FlowKeys.LevelNames].AsJsonArray;
                foreach (string levelName in tierLevels)
                {
                    List <string> columns = LevelParser.BreakMapIntoColumns(levelName);
                    columns.RemoveAt(columns.Count - 1); // remove flag at the end
                    List <string> simpleColumns = LevelParser.BreakColumnsIntoSimplifiedTokens(
                        columns,
                        blackBoard.ConfigUI.Config.Game);

                    levelColumns.Add(columns);
                    simplifiedLevelColumns.Add(simpleColumns);

                    NGramTrainer.Train(grammar, columns, skipFirst: true);
                    NGramTrainer.Train(simpleGrammar, simpleColumns, skipFirst: true);

                    if (blackBoard.ProgressIndex != i)
                    {
                        grammar.UpdateMemory(blackBoard.ConfigUI.Config.TieredGenerationMemoryUpdate);
                        levelColumns.Clear();
                        simplifiedLevelColumns.Clear();
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: ProfileTest.cs プロジェクト: bi3mer/PCGPlatformer
        private List <SimulationThread> GetSimulationThreads(string levelFlowPath, string name, Games game)
        {
            // We first get all the levels from the flow and then get the start
            // input from the first level in the sequence. Note that the first
            // we use the same start input but we don't want that to scew
            // results. To get around this, we use a flag in the ngram generator
            // which will not include the start output in the end result.
            List <List <string> >   levels     = BuildSimulator.GetLevels(levelFlowPath);
            List <string>           startInput = levels[0].GetRange(0, 10);
            List <SimulationThread> threads    = new List <SimulationThread>();

            for (int i = 1; i <= 6; ++i)
            {
                IGram gram = NGramFactory.InitGrammar(i);
                foreach (List <string> level in levels)
                {
                    NGramTrainer.Train(gram, level, skipFirst: true);
                }

                //threads.Add(BuildThread(gram, null, startInput, game, $"{name}_{Size}_ngram"));

                if (i != 1)
                {
                    gram = NGramFactory.InitHierarchicalNGram(i, 0.6f);
                    IGram simpleGram = NGramFactory.InitHierarchicalNGram(i, 0.6f);

                    IGram bgram = NGramFactory.InitBackOffNGram(i, 0.6f);
                    foreach (List <string> level in levels)
                    {
                        NGramTrainer.Train(gram, level, skipFirst: true);
                        NGramTrainer.Train(bgram, level, skipFirst: true);
                        NGramTrainer.Train(
                            simpleGram,
                            LevelParser.BreakColumnsIntoSimplifiedTokens(
                                level,
                                game),
                            skipFirst: true);
                    }

                    //threads.Add(BuildThread(gram, null, startInput, game, $"{name}_{Size}_heirarchical"));
                    threads.Add(BuildThread(gram, simpleGram, startInput, game, $"{name}_{Size}_simple_heirarchical"));

                    //threads.Add(BuildThread(bgram, null, startInput, game, $"{name}_{Size}_backoff"));
                    // threads.Add(BuildThread(bgram, simpleGram, startInput, game, $"{name}_{Size}_simple_backoff"));
                }
            }

            return(threads);
        }
コード例 #3
0
    private bool RunProceduralGeneration()
    {
        if (blackBoard.Reset)
        {
            if (blackBoard.ConfigUI.Config.HeiarchalEnabled)
            {
                blackBoard.DifficultyNGram = NGramFactory.InitHierarchicalNGram(
                    blackBoard.ConfigUI.Config.N,
                    blackBoard.ConfigUI.Config.HeiarchalMemory);

                blackBoard.SimpleDifficultyNGram = NGramFactory.InitHierarchicalNGram(
                    blackBoard.ConfigUI.Config.N,
                    blackBoard.ConfigUI.Config.HeiarchalMemory);
            }
            else if (blackBoard.ConfigUI.Config.BackOffEnabled)
            {
                blackBoard.DifficultyNGram = NGramFactory.InitBackOffNGram(
                    blackBoard.ConfigUI.Config.N,
                    blackBoard.ConfigUI.Config.BackOffMemory);

                blackBoard.SimpleDifficultyNGram = NGramFactory.InitBackOffNGram(
                    blackBoard.ConfigUI.Config.N,
                    blackBoard.ConfigUI.Config.BackOffMemory);
            }
            else
            {
                blackBoard.DifficultyNGram       = NGramFactory.InitGrammar(blackBoard.ConfigUI.Config.N);
                blackBoard.SimpleDifficultyNGram = NGramFactory.InitGrammar(blackBoard.ConfigUI.Config.N);
            }

            GenerateNGram();
            blackBoard.Reset = false;
        }
        else
        {
            if (blackBoard.DifficultyNGram == null)
            {
                if (blackBoard.ConfigUI.Config.HeiarchalEnabled)
                {
                    blackBoard.DifficultyNGram = NGramFactory.InitHierarchicalNGram(
                        blackBoard.ConfigUI.Config.N,
                        blackBoard.ConfigUI.Config.HeiarchalMemory);

                    blackBoard.SimpleDifficultyNGram = NGramFactory.InitHierarchicalNGram(
                        blackBoard.ConfigUI.Config.N,
                        blackBoard.ConfigUI.Config.HeiarchalMemory);
                }
                else if (blackBoard.ConfigUI.Config.BackOffEnabled)
                {
                    blackBoard.DifficultyNGram = NGramFactory.InitBackOffNGram(
                        blackBoard.ConfigUI.Config.N,
                        blackBoard.ConfigUI.Config.BackOffMemory);

                    blackBoard.SimpleDifficultyNGram = NGramFactory.InitBackOffNGram(
                        blackBoard.ConfigUI.Config.N,
                        blackBoard.ConfigUI.Config.BackOffMemory);
                }
                else
                {
                    blackBoard.DifficultyNGram       = NGramFactory.InitGrammar(blackBoard.ConfigUI.Config.N);
                    blackBoard.SimpleDifficultyNGram = NGramFactory.InitGrammar(blackBoard.ConfigUI.Config.N);
                }
            }

            if (grammar == null || blackBoard.ProgressIndex != previousIndex)
            {
                GenerateNGram();
            }
        }

        if (blackBoard.ConfigUI.Config.DifficultyNGramEnabled)
        {
            grammar.AddGrammar(blackBoard.DifficultyNGram);
        }

        return(GenerateLevel());
    }