public IGeneratorRunner GetGeneratorRunner(LevelDescriptionGrid2D <TNode> levelDescription)
        {
            if (benchmarkInitialization)
            {
                return(GetGeneratorRunnerWithInit(levelDescription));
            }

            var configuration = this.configuration.SmartClone();

            configuration.RoomsCanTouch = levelDescription.MinimumRoomDistance == 0;

            var mapDescription = levelDescription.GetMapDescription();

            var chainDecompositionOld = new BreadthFirstChainDecompositionOld <TNode>();
            var chainDecomposition    = new TwoStageChainDecomposition <TNode>(mapDescription, chainDecompositionOld);

            configuration.Chains = chainDecomposition.GetChains(levelDescription.GetGraph());
            configuration.SimulatedAnnealingConfiguration = new SimulatedAnnealingConfigurationProvider(new SimulatedAnnealingConfiguration()
            {
                MaxIterationsWithoutSuccess = 10000,
            });

            var layoutDrawer = new SVGLayoutDrawer <TNode>();

            var layoutGenerator = new DungeonGenerator <TNode>(mapDescription, configuration);

            layoutGenerator.InjectRandomGenerator(new Random(0));

            return(new LambdaGeneratorRunner(() =>
            {
                var simulatedAnnealingArgsContainer = new List <SimulatedAnnealingEventArgs>();

                void SimulatedAnnealingEventHandler(object sender, SimulatedAnnealingEventArgs eventArgs)
                {
                    simulatedAnnealingArgsContainer.Add(eventArgs);
                }

                layoutGenerator.OnSimulatedAnnealingEvent += SimulatedAnnealingEventHandler;
                var layout = layoutGenerator.GenerateLayout();
                layoutGenerator.OnSimulatedAnnealingEvent -= SimulatedAnnealingEventHandler;

                var additionalData = new AdditionalRunData <TNode>()
                {
                    SimulatedAnnealingEventArgs = simulatedAnnealingArgsContainer,
                    GeneratedLayoutSvg =
                        layout != null ? layoutDrawer.DrawLayout(layout, 800, forceSquare: true) : null,
                    GeneratedLayout = layout,
                };

                var generatorRun = new GeneratorRun <AdditionalRunData <TNode> >(layout != null, layoutGenerator.TimeTotal,
                                                                                 layoutGenerator.IterationsCount, additionalData);

                return generatorRun;
            }));
        }
        protected override DungeonGeneratorConfiguration <int> GetBasicConfiguration(NamedMapDescription namedMapDescription)
        {
            var configuration         = base.GetBasicConfiguration(namedMapDescription);
            var chainDecompositionOld = new BreadthFirstChainDecompositionOld <int>();
            var chainDecomposition    = new TwoStageChainDecomposition <int>(namedMapDescription.MapDescription, chainDecompositionOld);
            var chains = chainDecomposition.GetChains(namedMapDescription.MapDescription.GetGraph());

            configuration.Chains = chains;

            return(configuration);
        }
示例#3
0
        private DungeonGeneratorConfiguration <int> GetWithoutChainDecompositionConfiguration(NamedMapDescription namedMapDescription)
        {
            var chainDecompositionOld = new BreadthFirstChainDecompositionOld <int>();
            var chainDecomposition    = new Edgar.Legacy.Core.ChainDecompositions.TwoStageChainDecomposition <int>(namedMapDescription.MapDescription, chainDecompositionOld);

            var configuration = GetNewConfiguration(namedMapDescription);

            configuration.Chains = chainDecomposition.GetChains(namedMapDescription.MapDescription.GetGraph());

            return(configuration);
        }
示例#4
0
        private DungeonGeneratorConfiguration <int> GetOldConfiguration(NamedMapDescription namedMapDescription)
        {
            var chainDecompositionOld = new BreadthFirstChainDecompositionOld <int>();
            var chainDecomposition    = new TwoStageChainDecomposition <int>(namedMapDescription.MapDescription, chainDecompositionOld);

            var configuration = GetBasicConfiguration(namedMapDescription);

            configuration.Chains = chainDecomposition.GetChains(namedMapDescription.MapDescription.GetGraph());
            configuration.SimulatedAnnealingConfiguration = new SimulatedAnnealingConfigurationProvider(new SimulatedAnnealingConfiguration()
            {
                MaxIterationsWithoutSuccess = 10000,
            });

            return(configuration);
        }
 protected override void CreateConcrete()
 {
     chainDecomposition = new BreadthFirstChainDecompositionOld <int>();
 }
示例#6
0
        public void Run()
        {
            var count  = 20;
            var name   = "edges_0_3";
            var graphs = GetGraphs(count, name);

            var inputs = new List <DungeonGeneratorInput <int> >();
            var chainDecompositionOld = new BreadthFirstChainDecompositionOld <int>();

            for (var i = 0; i < graphs.Count; i++)
            {
                var graph = graphs[i];

                for (int j = 0; j < 1; j++)
                {
                    var withCorridors      = j == 1;
                    var mapDescription     = GetMapDescription(graph, withCorridors);
                    var chainDecomposition = new TwoStageChainDecomposition <int>(mapDescription, chainDecompositionOld);

                    inputs.Add(new DungeonGeneratorInput <int>($"RandomGraph {i} {(withCorridors ? "wc" : "")}", mapDescription, new DungeonGeneratorConfiguration <int>()
                    {
                        EarlyStopIfIterationsExceeded = 20000,
                        // Chains = chainDecomposition.GetChains(mapDescription.GetGraph()),
                        SimulatedAnnealingConfiguration = new SimulatedAnnealingConfigurationProvider(new SimulatedAnnealingConfiguration()
                        {
                            MaxIterationsWithoutSuccess = 150
                        })
                    }, null));
                }
            }

            var benchmarkRunner   = new BenchmarkRunner <IMapDescription <int> >();
            var benchmarkScenario = new BenchmarkScenario <IMapDescription <int> >("RandomGraphs", input =>
            {
                var layoutDrawer          = new SVGLayoutDrawer <int>();
                var dungeonGeneratorInput = (DungeonGeneratorInput <int>)input;
                var layoutGenerator       = new DungeonGenerator <int>(input.MapDescription, dungeonGeneratorInput.Configuration);
                layoutGenerator.InjectRandomGenerator(new Random(0));

                return(new LambdaGeneratorRunner(() =>
                {
                    var simulatedAnnealingArgsContainer = new List <SimulatedAnnealingEventArgs>();
                    void SimulatedAnnealingEventHandler(object sender, SimulatedAnnealingEventArgs eventArgs)
                    {
                        simulatedAnnealingArgsContainer.Add(eventArgs);
                    }

                    layoutGenerator.OnSimulatedAnnealingEvent += SimulatedAnnealingEventHandler;
                    var layout = layoutGenerator.GenerateLayout();
                    layoutGenerator.OnSimulatedAnnealingEvent -= SimulatedAnnealingEventHandler;

                    var additionalData = new AdditionalRunData()
                    {
                        SimulatedAnnealingEventArgs = simulatedAnnealingArgsContainer,
                        GeneratedLayoutSvg = layout != null ? layoutDrawer.DrawLayout(layout, 800, forceSquare: true) : null,
                        GeneratedLayout = layout,
                    };

                    var generatorRun = new GeneratorRun <AdditionalRunData>(layout != null, layoutGenerator.TimeTotal, layoutGenerator.IterationsCount, additionalData);

                    return generatorRun;
                }));
            });