Esempio n. 1
0
        private Tuple <List <string>, List <string> > GetColumnsSemiGuaranteed(ICompiledGram compiled, ICompiledGram simpleCompiled)
        {
            List <string> columns;
            List <string> simplified;

            if (simplifiedGram == null)
            {
                columns    = NGramGenerator.Generate(compiled, startInput, size, includeStart: false);
                simplified = LevelParser.BreakColumnsIntoSimplifiedTokens(
                    columns,
                    game);
            }
            else
            {
                simplified = NGramGenerator.GenerateBestAttempt(
                    simpleCompiled,
                    LevelParser.BreakColumnsIntoSimplifiedTokens(startInput, game),
                    size,
                    maxAttempts);

                Games localGame = game;
                columns = NGramGenerator.GenerateRestricted(
                    compiled,
                    startInput,
                    simplified,
                    (inColumn) =>
                {
                    return(LevelParser.ClassifyColumn(inColumn, localGame));
                },
                    includeStart: false);
            }

            return(new Tuple <List <string>, List <string> >(columns, simplified));
        }
Esempio n. 2
0
    private void UpdateDifficultyNGram()
    {
        Vector3 playerPosition = blackBoard.LevelInfo.Player.transform.position;
        int     toRight        = blackBoard.ConfigUI.Config.DifficultyNGramRightColumns;
        int     toLeft         = blackBoard.ConfigUI.Config.DifficultyNGramLeftColumns;
        Tilemap tilemap        = blackBoard.Tilemap;

        Vector3Int tilePosition = tilemap.WorldToCell(playerPosition);

        int x    = Math.Max(tilePosition.x - toLeft, tilemap.cellBounds.xMin);
        int xMax = Math.Min(tilePosition.x + toRight, tilemap.cellBounds.xMax - 1);

        blackBoard.DifficultyNGram.UpdateMemory(blackBoard.ConfigUI.Config.DifficultyNGramMemoryUpdate);

        List <string> difficultPart = blackBoard.LevelColumns.GetRange(x, xMax - x + 1);

        NGramTrainer.Train(blackBoard.DifficultyNGram, difficultPart);

        if (blackBoard.ConfigUI.Config.UsingSimplifiedNGram)
        {
            blackBoard.SimpleDifficultyNGram.UpdateMemory(blackBoard.ConfigUI.Config.DifficultyNGramMemoryUpdate);
            NGramTrainer.Train(
                blackBoard.SimpleDifficultyNGram,
                LevelParser.BreakColumnsIntoSimplifiedTokens(
                    difficultPart,
                    blackBoard.ConfigUI.Config.Game));
        }
    }
Esempio n. 3
0
        public void TestParseCustomLevelPlatformEnemy()
        {
            List <string> columns = new List <string>()
            {
                "--------------------------------------A-----------------"
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[0]);

            columns.Add("------------------------------------Bbb-----------------");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[1]);

            columns.Add("-------------------------------------bbb---------------C");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[1]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[2]);

            columns.Add("---------------------------------------------Ab---------");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[1]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[2]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[3]);
        }
Esempio n. 4
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();
                    }
                }
            }
        }
    }
Esempio n. 5
0
        public void TestParseVGLCLevelPlatformOptionalEnemy()
        {
            List <string> columns = new List <string>()
            {
                "---Ab----b"
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioLand);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformOptionalEnemy, result[0]);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        public void TestParseCustomLevelLinear()
        {
            List <string> columns = new List <string>()
            {
                "--------------------------------------b-----------------"
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SimplifiedColumns.Linear, result[0]);
            columns.Add("--------------------------------------b-------$$--------");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(SimplifiedColumns.Linear, result[0]);
            Assert.AreEqual(SimplifiedColumns.Linear, result[1]);
        }
Esempio n. 8
0
        public void TestParseVGLCLevelPlatformEnemy()
        {
            List <string> columns = new List <string>()
            {
                "--------Abb"
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioLand);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[0]);

            columns.Add("-------C---");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioLand);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[1]);
        }
Esempio n. 9
0
        public void TestParseVGLCLevelLinearEnemy()
        {
            List <string> columns = new List <string>()
            {
                "------A----b"
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros2);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[0]);

            columns.Add("----------Bb");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros2);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[1]);

            columns.Add("C----------b");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros2);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[1]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[2]);

            columns.Add("-----D-----b");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros2);
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[1]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[2]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[3]);

            columns.Add("B-C--DA----b");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros2);
            Assert.AreEqual(5, result.Count);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[0]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[1]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[2]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[3]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[4]);
        }
Esempio n. 10
0
        public void TestParseCustomTogether()
        {
            List <string> columns = new List <string>()
            {
                "--------------------------------------b-----------------",
                "-------D------------------------------b-----------------",
                "--------------------------------------------------------",
                "---------------------------------------------A----------",
                "--------------------------------------b----------------b",
                "-------------------------------Cb-----b-----------------",
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.Custom);

            Assert.AreEqual(6, result.Count);
            Assert.AreEqual(SimplifiedColumns.Linear, result[0]);
            Assert.AreEqual(SimplifiedColumns.LinearEnemy, result[1]);
            Assert.AreEqual(SimplifiedColumns.PlatformForced, result[2]);
            Assert.AreEqual(SimplifiedColumns.PlatformForcedEnemy, result[3]);
            Assert.AreEqual(SimplifiedColumns.PlatformOptional, result[4]);
            Assert.AreEqual(SimplifiedColumns.PlatformOptionalEnemy, result[5]);
        }
Esempio n. 11
0
        public void TestParseVGLCLevelLinear()
        {
            List <string> columns = new List <string>()
            {
                "-----------b"
            };
            List <string> result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(SimplifiedColumns.Linear, result[0]);

            columns.Add("-----------b");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(SimplifiedColumns.Linear, result[0]);
            Assert.AreEqual(SimplifiedColumns.Linear, result[1]);

            columns.Add("---$$$$----b");
            result = LevelParser.BreakColumnsIntoSimplifiedTokens(columns, Games.SuperMarioBros);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(SimplifiedColumns.Linear, result[0]);
            Assert.AreEqual(SimplifiedColumns.Linear, result[1]);
            Assert.AreEqual(SimplifiedColumns.Linear, result[2]);
        }