static void QualityTests(int mapSize, int iter, int subIter, string fileName) { AStarDiagnostic diagnostic; using (StreamWriter file = new StreamWriter(fileName)) { for (int i = 0; i < iter; i++) { Map.Map map = new Map.Map(mapSize, new MapSeed((int)(mapSize / 2.5), (int)(mapSize / 5.0), (int)(mapSize / 7.5)), i); for (int j = 0; j < subIter; j++) { Write($"{i}\t{j}\t"); MapField start = map[rand.Next(mapSize), rand.Next(mapSize)]; MapField stop = map[rand.Next(mapSize), rand.Next(mapSize)]; while (!start.IsAvaliable) { start = map[rand.Next(mapSize), rand.Next(mapSize)]; } while (!stop.IsAvaliable || stop == start) { stop = map[rand.Next(mapSize), rand.Next(mapSize)]; } Write("E\t"); diagnostic = new AStarDiagnostic(new Stopwatch()); diagnostic.Time.Start(); try { AStar(start, stop, EuclideanDistance, ref diagnostic); } catch (FieldNotAvaliableException) { } diagnostic.Time.Stop(); file.WriteLine($"{i}\tEucildesian\t{diagnostic.Time.Elapsed.TotalMilliseconds}\t{diagnostic.Iterations}\t{diagnostic.TotalCost}\t{diagnostic.TotalLength}"); Write("M\t"); diagnostic = new AStarDiagnostic(new Stopwatch()); diagnostic.Time.Start(); try { AStar(start, stop, ManhattanDistance, ref diagnostic); } catch (FieldNotAvaliableException) { } diagnostic.Time.Stop(); file.WriteLine($"{i}\tManhattan\t{diagnostic.Time.Elapsed.TotalMilliseconds}\t{diagnostic.Iterations}\t{diagnostic.TotalCost}\t{diagnostic.TotalLength}"); Write("N\t"); diagnostic = new AStarDiagnostic(new Stopwatch()); diagnostic.Time.Start(); try { AStar(start, stop, NullDistance, ref diagnostic); } catch (FieldNotAvaliableException) { } diagnostic.Time.Stop(); file.WriteLine($"{i}\tNull\t{diagnostic.Time.Elapsed.TotalMilliseconds}\t{diagnostic.Iterations}\t{diagnostic.TotalCost}\t{diagnostic.TotalLength}"); WriteLine("END"); file.Flush(); } GC.Collect(); } } }
static void PerformanceTests(int mapSize, int iter, string fileName) { AStarDiagnostic diagnostic; using (StreamWriter file = new StreamWriter(fileName)) { for (int i = 0; i < iter + 1; i++) { if (i == 105) { continue; } Write($"{i}\t"); Map.Map map = new Map.Map(mapSize, new MapSeed((int)(mapSize / 2.5), (int)(mapSize / 5.0), (int)(mapSize / 7.5)), i); RenderTexture render = new RenderTexture((uint)(mapSize * MapField.ScreenSize), (uint)(mapSize * MapField.ScreenSize), true) { Smooth = true, }; render.Draw(map); render.Texture.CopyToImage().SaveToFile($@"map_{i}.png"); MapField start = map.First(field => field.IsAvaliable); MapField stop = map.Reverse().First(field => field.IsAvaliable); Write("E\t"); diagnostic = new AStarDiagnostic(new Stopwatch()); diagnostic.Time.Start(); try { AStar(start, stop, EuclideanDistance, ref diagnostic); } catch (FieldNotAvaliableException) { } diagnostic.Time.Stop(); file.WriteLine($"{i}\tEucildesian\t{diagnostic.Time.Elapsed.TotalMilliseconds}\t{diagnostic.Iterations}\t{diagnostic.TotalCost}\t{diagnostic.TotalLength}"); Write("M\t"); diagnostic = new AStarDiagnostic(new Stopwatch()); diagnostic.Time.Start(); try { AStar(start, stop, ManhattanDistance, ref diagnostic); } catch (FieldNotAvaliableException) { } diagnostic.Time.Stop(); file.WriteLine($"{i}\tManhattan\t{diagnostic.Time.Elapsed.TotalMilliseconds}\t{diagnostic.Iterations}\t{diagnostic.TotalCost}\t{diagnostic.TotalLength}"); Write("N\t"); diagnostic = new AStarDiagnostic(new Stopwatch()); diagnostic.Time.Start(); try { AStar(start, stop, NullDistance, ref diagnostic); } catch (FieldNotAvaliableException) { } diagnostic.Time.Stop(); file.WriteLine($"{i}\tNull\t{diagnostic.Time.Elapsed.TotalMilliseconds}\t{diagnostic.Iterations}\t{diagnostic.TotalCost}\t{diagnostic.TotalLength}"); WriteLine("END"); file.Flush(); GC.Collect(); } } }