public MapDescription <int> GetMapDescription() { var mapDescription = new MapDescription <int>(); mapDescription.SetupWithGraph(GraphsDatabase.GetExample1()); // Add room shapes var doorMode = new OverlapMode(1, 1); var squareRoom = new RoomDescription( GridPolygon.GetSquare(8), doorMode ); var rectangleRoom = new RoomDescription( GridPolygon.GetRectangle(6, 10), doorMode ); mapDescription.AddRoomShapes(squareRoom); mapDescription.AddRoomShapes(rectangleRoom); // Setup corridor shapes var corridorRoom = new RoomDescription( GridPolygon.GetSquare(1), new SpecificPositionsMode(new List <OrthogonalLine>() { new OrthogonalLine(new IntVector2(0, 0), new IntVector2(1, 0)), new OrthogonalLine(new IntVector2(0, 1), new IntVector2(1, 1)) }) ); mapDescription.AddCorridorShapes(corridorRoom); // Enable corridors mapDescription.SetWithCorridors(true, new List <int>() { 1 }); return(mapDescription); }
public virtual List <NamedGraph> GetGraphs() { var allGraphs = new Dictionary <string, Tuple <string, IGraph <int> > >() { { "1", Tuple.Create("Example 1 (fig. 1)", GraphsDatabase.GetExample1()) }, { "2", Tuple.Create("Example 2 (fig. 7 top)", GraphsDatabase.GetExample2()) }, { "3", Tuple.Create("Example 3 (fig. 7 bottom)", GraphsDatabase.GetExample3()) }, { "4", Tuple.Create("Example 4 (fig. 8)", GraphsDatabase.GetExample4()) }, { "5", Tuple.Create("Example 5 (fig. 9)", GraphsDatabase.GetExample5()) }, }; var graphs = Options .Graphs .Select(x => new NamedGraph(allGraphs[x].Item2, allGraphs[x].Item1)) .ToList(); foreach (var graphSet in Options.GraphSets) { graphs.AddRange(GetGraphSet(graphSet, Options.GraphSetCount)); } return(graphs); }
public static List <Tuple <string, MapDescription <int> > > GetMapDescriptionsSet(IntVector2 scale, bool enableCorridors, List <int> offsets = null) { return(new List <Tuple <string, MapDescription <int> > >() { new Tuple <string, MapDescription <int> >("Example 1 (fig. 1)", new MapDescription <int>() .SetupWithGraph(GraphsDatabase.GetExample1()) .AddClassicRoomShapes(scale) .AddCorridorRoomShapes(offsets, enableCorridors) ), new Tuple <string, MapDescription <int> >("Example 2 (fig. 7 top)", new MapDescription <int>() .SetupWithGraph(GraphsDatabase.GetExample2()) .AddClassicRoomShapes(scale) .AddCorridorRoomShapes(offsets, enableCorridors) ), new Tuple <string, MapDescription <int> >("Example 3 (fig. 7 bottom)", new MapDescription <int>() .SetupWithGraph(GraphsDatabase.GetExample3()) .AddClassicRoomShapes(scale) .AddCorridorRoomShapes(offsets, enableCorridors) ), new Tuple <string, MapDescription <int> >("Example 4 (fig. 8)", new MapDescription <int>() .SetupWithGraph(GraphsDatabase.GetExample4()) .AddClassicRoomShapes(scale) .AddCorridorRoomShapes(offsets, enableCorridors) ), new Tuple <string, MapDescription <int> >("Example 5 (fig. 9)", new MapDescription <int>() .SetupWithGraph(GraphsDatabase.GetExample5()) .AddClassicRoomShapes(scale) .AddCorridorRoomShapes(offsets, enableCorridors) ), }); }
public static void RunOld(Options options) { // TODO: make better Directory = Path.Combine("DungeonGeneratorEvolutions", FileNamesHelper.PrefixWithTimestamp(options.Name)); System.IO.Directory.CreateDirectory(Directory); Logger = new Logger(new ConsoleLoggerHandler(), new FileLoggerHandler(Path.Combine(Directory, "log.txt"))); var allGraphs = new Dictionary <string, Tuple <string, IGraph <int> > >() { { "1", Tuple.Create("Example 1 (fig. 1)", GraphsDatabase.GetExample1()) }, { "2", Tuple.Create("Example 2 (fig. 7 top)", GraphsDatabase.GetExample2()) }, { "3", Tuple.Create("Example 3 (fig. 7 bottom)", GraphsDatabase.GetExample3()) }, { "4", Tuple.Create("Example 4 (fig. 8)", GraphsDatabase.GetExample4()) }, { "5", Tuple.Create("Example 5 (fig. 9)", GraphsDatabase.GetExample5()) }, }; var mapDescriptions = new Dictionary <string, Tuple <string, MapDescription <int> > >() { { "gungeon_1_1", Tuple.Create("Gungeon 1_1", LoadMapDescription("gungeon_1_1")) }, { "gungeon_1_2", Tuple.Create("Gungeon 1_2", LoadMapDescription("gungeon_1_2")) }, { "gungeon_2_1", Tuple.Create("Gungeon 2_1", LoadMapDescription("gungeon_2_1")) }, { "gungeon_2_2", Tuple.Create("Gungeon 2_2", LoadMapDescription("gungeon_2_2")) }, // { "gungeon_2_4", Tuple.Create("Gungeon 2_4", LoadMapDescription("gungeon_2_4")) }, }; var allAnalyzers = new Dictionary <string, Func <IMapDescription <int>, IPerformanceAnalyzer <DungeonGeneratorConfiguration <int>, Individual <int> > > >() { { "MaxStageTwoFailures", (_) => new MaxStageTwoFailuresAnalyzer <DungeonGeneratorConfiguration <int>, GeneratorData>() }, { "MaxIterations", (_) => new MaxIterationsAnalyzer <DungeonGeneratorConfiguration <int>, GeneratorData>() }, { "ChainMerge", (_) => new ChainMergeAnalyzer <DungeonGeneratorConfiguration <int>, int, GeneratorData>() }, { "ChainOrder", (_) => new ChainOrderAnalyzer <DungeonGeneratorConfiguration <int>, int, GeneratorData>() }, { "MaxBranching", (_) => new MaxBranchingAnalyzer <DungeonGeneratorConfiguration <int>, GeneratorData>() }, { "ChainDecomposition", (mapDescription) => new ChainDecompositionAnalyzer <DungeonGeneratorConfiguration <int>, int, GeneratorData>(mapDescription) }, }; // Select graphs var graphs = options.Graphs.Count() != 0 ? options .Graphs .Select(x => allGraphs[x]) .ToList() : allGraphs.Values.ToList(); graphs = options .Graphs .Select(x => allGraphs[x]) .ToList(); // Select analyzers var analyzers = options.Mutations.Count() != 0 ? options .Mutations .Select(x => allAnalyzers[x]) .ToList() : allAnalyzers.Values.ToList(); var inputs = new List <Input>(); foreach (var graphPair in graphs) { foreach (var corridorOffset in options.CorridorOffsets) { var corridorOffsets = corridorOffset.Split(",").Select(x => int.Parse(x)).ToList(); var withCorridors = corridorOffsets[0] != 0; var canTouch = options.CanTouch || !withCorridors; var name = MapDescriptionUtils.GetInputName(graphPair.Item1, options.Scale, withCorridors, corridorOffsets, canTouch); var graph = graphPair.Item2; var basicRoomTemplates = MapDescriptionUtils.GetBasicRoomTemplates(options.Scale); var basicRoomDescription = new BasicRoomDescription(basicRoomTemplates); var corridorRoomTemplates = withCorridors ? MapDescriptionUtils.GetCorridorRoomTemplates(corridorOffsets) : null; var corridorRoomDescription = withCorridors ? new CorridorRoomDescription(corridorRoomTemplates) : null; var mapDescription = MapDescriptionUtils.GetBasicMapDescription(graph, basicRoomDescription, corridorRoomDescription, withCorridors); inputs.Add(new Input() { Name = name, MapDescription = mapDescription, Configuration = new DungeonGeneratorConfiguration <int>() { RoomsCanTouch = canTouch, } }); } } foreach (var mapDescriptionKey in options.MapDescriptions) { var mapDescription = mapDescriptions[mapDescriptionKey]; inputs.Add(new Input() { Name = mapDescription.Item1, MapDescription = mapDescription.Item2, Configuration = new DungeonGeneratorConfiguration <int>() { RoomsCanTouch = options.CanTouch, } }); } var resultsDict = new Dictionary <Input, Result>(); var partitioner = Partitioner.Create(inputs, EnumerablePartitionerOptions.NoBuffering); Parallel.ForEach(partitioner, new ParallelOptions { MaxDegreeOfParallelism = options.MaxThreads }, input => { lock (Logger) { Logger.WriteLine($"Started {input.Name}"); } var result = RunEvolution(input, options, analyzers.Select(x => x(input.MapDescription)).ToList()); lock (Logger) { Logger.WriteLine($"Ended {input.Name}"); } lock (resultsDict) { resultsDict[input] = result; } }); var results = inputs.Select(x => resultsDict[x]).ToList(); Logger.WriteLine(); AnalyzeMutations(results.ToList()); var inputsNewConfigurations = results.Select(x => new DungeonGeneratorInput <int>(x.Input.Name, x.Input.MapDescription, x.NewConfiguration)); var inputsOldConfigurations = results.Select(x => new DungeonGeneratorInput <int>(x.Input.Name, x.Input.MapDescription, x.Input.Configuration)); var benchmarkRunner = new BenchmarkRunner <IMapDescription <int> >(); var benchmarkScenarioNew = new BenchmarkScenario <IMapDescription <int> >("NewConfigurations", GetGeneratorRunnerFactory); var benchmarkScenarioOld = new BenchmarkScenario <IMapDescription <int> >("OldConfigurations", GetGeneratorRunnerFactory); var resultSaver = new BenchmarkResultSaver(); var scenarioResultNew = benchmarkRunner.Run(benchmarkScenarioNew, inputsNewConfigurations, options.FinalEvaluationIterations, new BenchmarkOptions() { WithConsolePreview = false, }); resultSaver.SaveResultDefaultLocation(scenarioResultNew, directory: Directory); var scenarioResultOld = benchmarkRunner.Run(benchmarkScenarioOld, inputsOldConfigurations, options.FinalEvaluationIterations, new BenchmarkOptions() { WithConsolePreview = false, }); resultSaver.SaveResultDefaultLocation(scenarioResultOld, directory: Directory); }
public MapDescription <int> GetMapDescription() { const bool useLongCorridors = false; const bool useLShapedCorridors = false; const bool useWideCorridors = false; // Create basic room templates and room description var doorMode = new SimpleDoorMode(1, 1); var squareRoom = new RoomTemplate( PolygonGrid2D.GetSquare(8), doorMode ); var rectangleRoom = new RoomTemplate( PolygonGrid2D.GetRectangle(6, 10), doorMode, new List <TransformationGrid2D>() { TransformationGrid2D.Identity, TransformationGrid2D.Rotate90 } ); var basicRoomDescription = new BasicRoomDescription(new List <RoomTemplate>() { squareRoom, rectangleRoom }); // Basic corridor shape var corridorRoom1x2 = new RoomTemplate( PolygonGrid2D.GetRectangle(1, 2), new ManualDoorMode(new List <OrthogonalLineGrid2D>() { new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(1, 0)), new OrthogonalLineGrid2D(new Vector2Int(0, 2), new Vector2Int(1, 2)) }), new List <TransformationGrid2D>() { TransformationGrid2D.Identity, TransformationGrid2D.Rotate90 } ); var corridorRoomDescription = new CorridorRoomDescription(new List <RoomTemplate>() { corridorRoom1x2 }); // Add longer corridor if (useLongCorridors) { var corridorRoom1x4 = new RoomTemplate( PolygonGrid2D.GetRectangle(1, 4), new ManualDoorMode(new List <OrthogonalLineGrid2D>() { new OrthogonalLineGrid2D(new Vector2Int(0, 0), new Vector2Int(1, 0)), new OrthogonalLineGrid2D(new Vector2Int(0, 4), new Vector2Int(1, 4)) }), new List <TransformationGrid2D>() { TransformationGrid2D.Identity, TransformationGrid2D.Rotate90 } ); corridorRoomDescription.RoomTemplates.Add(corridorRoom1x4); } // Add l-shaped corridor if (useLShapedCorridors) { var corridorRoomLShaped = new RoomTemplate( new PolygonGrid2DBuilder() .AddPoint(0, 2) .AddPoint(0, 3) .AddPoint(3, 3) .AddPoint(3, 0) .AddPoint(2, 0) .AddPoint(2, 2) .Build(), new ManualDoorMode(new List <OrthogonalLineGrid2D>() { new OrthogonalLineGrid2D(new Vector2Int(0, 2), new Vector2Int(0, 3)), new OrthogonalLineGrid2D(new Vector2Int(2, 0), new Vector2Int(3, 0)) }), TransformationGrid2DHelper.GetAllTransformationsOld().ToList() ); corridorRoomDescription.RoomTemplates.Add(corridorRoomLShaped); } // Add wide corridor if (useWideCorridors) { var corridorWide = new RoomTemplate( new PolygonGrid2DBuilder() .AddPoint(1, 0) .AddPoint(1, 1) .AddPoint(0, 1) .AddPoint(0, 4) .AddPoint(1, 4) .AddPoint(1, 5) .AddPoint(2, 5) .AddPoint(2, 4) .AddPoint(3, 4) .AddPoint(3, 1) .AddPoint(2, 1) .AddPoint(2, 0) .Build(), new ManualDoorMode(new List <OrthogonalLineGrid2D>() { new OrthogonalLineGrid2D(new Vector2Int(1, 0), new Vector2Int(2, 0)), new OrthogonalLineGrid2D(new Vector2Int(1, 5), new Vector2Int(2, 5)) }), TransformationGrid2DHelper.GetAllTransformationsOld().ToList() ); corridorRoomDescription.RoomTemplates.Add(corridorWide); } // Create map description var mapDescription = new MapDescription <int>(); var graph = GraphsDatabase.GetExample1(); // Add non-corridor rooms foreach (var room in graph.Vertices) { mapDescription.AddRoom(room, basicRoomDescription); } // We need to somehow identify our corridor rooms // Here we simply number them and keep track which was the last used number var counter = graph.VerticesCount; foreach (var connection in graph.Edges) { if (true) { if (true) { if (connection.From % 2 == 0 && connection.To % 2 == 0) { // We manually insert a new node between each neighboring nodes in the graph mapDescription.AddRoom(counter, corridorRoomDescription); // And instead of connecting the rooms directly, we connect them to the corridor room mapDescription.AddConnection(connection.From, counter); mapDescription.AddConnection(connection.To, counter); counter++; } else { mapDescription.AddConnection(connection.From, connection.To); } } else { var desc1 = new CorridorRoomDescription(new List <RoomTemplate>() { corridorRoomDescription.RoomTemplates[0] }); var desc2 = new CorridorRoomDescription(new List <RoomTemplate>() { corridorRoomDescription.RoomTemplates[1] }); // We manually insert a new node between each neighboring nodes in the graph mapDescription.AddRoom(counter, connection.From % 2 == 0 && connection.To % 2 == 0 ? desc2 : desc1); // And instead of connecting the rooms directly, we connect them to the corridor room mapDescription.AddConnection(connection.From, counter); mapDescription.AddConnection(connection.To, counter); counter++; } } else { // We manually insert a new node between each neighboring nodes in the graph mapDescription.AddRoom(counter, corridorRoomDescription); // And instead of connecting the rooms directly, we connect them to the corridor room mapDescription.AddConnection(connection.From, counter); mapDescription.AddConnection(connection.To, counter); counter++; } } return(mapDescription); }