public void SaveAndLoad() { AlgorithmPalette p_original = AlgorithmPalette.DefaultPalette( AlgorithmPluginEnumerator.GetAllLoadedAlgorithms()); DungeonGenerator generator = TestHelpers.GetTestDungeonGenerator(); Assert.IsNotNull(p_original); AlgorithmPaletteSerializer serializer = new AlgorithmPaletteSerializer(); string paletteFile = System.IO.Path.GetTempFileName(); serializer.Save(p_original, paletteFile, FileMode.Create); Assert.IsTrue(File.Exists(paletteFile)); AlgorithmPalette p_loaded = serializer.Load(paletteFile); Assert.IsNotNull(p_loaded); Assert.AreEqual(p_original.Keys.Count, p_loaded.Keys.Count); Assert.IsTrue(Enumerable.SequenceEqual(p_original.Keys, p_loaded.Keys)); foreach (var k in p_original.Keys) { Assert.AreEqual(p_original[k].Info, p_loaded[k].Info); Assert.AreEqual(p_original[k].PaletteColor, p_loaded[k].PaletteColor); } File.Delete(paletteFile); }
public void RunWithoutMask() { Random r = new Random(); var allAlgs = AlgorithmPluginEnumerator.GetAllLoadedAlgorithms(); foreach (var algProto in allAlgs) { var runs = new List <AlgorithmRun> { new AlgorithmRun() { Alg = algProto.Clone() as IAlgorithm, Context = new AlgorithmContextBase() { R = new AlgorithmRandom(r.Next()) } } }; var generator = new DungeonGenerator(); generator.Options = new DungeonGenerator.DungeonGeneratorOptions() { DoReset = true, EgressConnections = null, Width = 25, Height = 25, AlgRuns = runs }; var dungeon = generator.Generate(); } }
public virtual IAlgorithm CreateInstance() { IAlgorithm alg = AlgorithmPluginEnumerator.GetAlgorithm(Type.ConvertToType(true)); if (null != alg && alg.TakesParameters) { alg.Parameters = this.Parameters; } return(alg); }
public static IEditableParameter AsEditable(this IAlgorithm alg) { return(new EditableParameterBase() { ParamName = alg.Name, Description = "TODO Add description attributes to algorithms", // TODO Should be same as AlgorithmParameter::GetDefault() Default = AlgorithmPluginEnumerator.GetAlgorithm(alg.GetType()), ValueType = typeof(IAlgorithm), Value = alg, Property = null }); }
public void ExportForPdn() { AlgorithmPalette palette = AlgorithmPalette.DefaultPalette( AlgorithmPluginEnumerator.GetAllLoadedAlgorithms()); Assert.IsNotNull(palette); AlgorithmPaletteSerializer serializer = new AlgorithmPaletteSerializer(); string paletteFile = System.IO.Path.GetTempFileName(); serializer.ExportForPdn(palette, paletteFile, FileMode.Create); Assert.IsTrue(File.Exists(paletteFile)); // TODO actually inspect PDN template file }
public override IAlgorithm CreateInstance() { CompositeAlgorithm alg = AlgorithmPluginEnumerator.GetAlgorithm(Type.ConvertToType(true)) as CompositeAlgorithm; if (alg == null) { throw new Exception("Failed to create composite algorithm from composite algorithm info"); } alg.Algorithms = new AlgorithmList(); alg.Algorithms.AddRange(this.Algorithms.Select(info => info.ToInstance())); alg.CompositeName = this.CompositeName; return(alg); }
public void AllAlgorithmsDefaultParams() { foreach (var algProto in AlgorithmPluginEnumerator.GetAllLoadedAlgorithms()) { IList <AlgorithmRun> runs = new List <AlgorithmRun>() { new AlgorithmRun() { Alg = algProto.Clone() as IAlgorithm, Context = new AlgorithmContextBase() { Mask = _dungeonMask_default, R = _r } }, }; Dungeon d = null; try { var generator = CreateDefaultTestGenerator(runs); d = generator.Generate(); } catch (NotImplementedException) { // If the algorithm is not implemented, that doesn't mean the // renderer is broken, so skip this Algorithm. continue; } Assert.IsNotNull(d); DungeonTileRenderer renderer = new DungeonTileRenderer(); using (Image renderedDungeon = renderer.Render(d)) { Assert.IsNotNull(renderedDungeon); string tempFile = System.IO.Path.GetTempFileName(); renderedDungeon.Save(tempFile, ImageFormat.Bmp); Assert.IsTrue(System.IO.File.Exists(tempFile)); System.IO.File.Delete(tempFile); } } }
public void RunWithDefaultParams() { IEnumerable <IAlgorithm> allAlgs = AlgorithmPluginEnumerator.GetAllLoadedAlgorithms(); foreach (var algProto in allAlgs) { IList <AlgorithmRun> runs = new List <AlgorithmRun>() { new AlgorithmRun() { Alg = algProto.Clone() as IAlgorithm, Context = new AlgorithmContextBase() { Mask = _dungeonMask_default, R = _r } }, }; var generator = CreateDefaultTestGenerator(runs); try { Dungeon d = generator.Generate(); #if RENDER_OUTPUT DungeonTileRenderer renderer = new DungeonTileRenderer(); using (Image renderedDungeon = renderer.Render(d)) { renderedDungeon.Save(String.Format("dungeon_{0}.bmp", algProto.Name), ImageFormat.Bmp); } #endif } catch (NotImplementedException) { Console.WriteLine("Skipping {0} as it is not implemented", algProto.Name); continue; } } }
public void RunHugeDungeon() { const int hugeSize = 37; bool[,] hugeMask = new bool[hugeSize, hugeSize]; for (int y = 0; y < hugeMask.GetLength(0); ++y) { for (int x = 0; x < hugeMask.GetLength(1); ++x) { hugeMask[y, x] = true; } } var hugeContext = new AlgorithmContextBase() { Mask = hugeMask, R = _r }; foreach (var algProto in AlgorithmPluginEnumerator.GetAllLoadedAlgorithms()) { IList <AlgorithmRun> runs = new List <AlgorithmRun>() { new AlgorithmRun() { Alg = algProto.Clone() as IAlgorithm, Context = hugeContext }, }; var generator = CreateDefaultTestGenerator(runs); generator.Options.Height = hugeSize; generator.Options.Width = hugeSize; generator.Options.DoReset = true; Dungeon d = generator.Generate(); } }
public override object GetDefault() { return(AlgorithmPluginEnumerator.GetAlgorithm(DefaultType)); }
private static IAlgorithm FindAlgorithm(string typeName) { return(AlgorithmPluginEnumerator.GetAlgorithm(typeName)); }