private void SelfTest(int height, int width, MeshType meshType, bool extensive) { Output(string.Format("SelfTesting {0}, {1}, {2}, {3}", height, width, meshType, extensive)); List<string> codes = new List<string>{"S", "SC", "SCO", "SCOM", "SC+OM", "SC+EOM", "SC+EOMP", "SC+EOMP+", "FC+EOMP+"}; List<string> extraCodes = new List<string>{"SI", "SIC", "SIO", "SM", "SIM", "SOM", "SP", "SP+", "SC+EP", "SE", "SEP", "SC+E", "SCE", "SCP"}; try { int solvedCount=0; for (int i = 0; i < (extensive ? 100 : 5); i++) { Mesh m = new Mesh(width, height, meshType); m.SetRatingCodeOptions("F"); m.GenerateBoringFraction = 0.5/height; m.GenerateLengthFraction = 0.7; m.Generate(); bool solved = false; int lastDepth = int.MaxValue; foreach (string code_in in codes) { bool solvedByCode = false; for (int j = 0; j < (extensive ? height * height : 1); j++ ) { string code = code_in; if (extensive) code += (j-1).ToString(); m.Clear(); m.SetRatingCodeOptions(code); SolveState result = m.TrySolve(); if (result == SolveState.Solved) { solvedByCode = true; if (!solved) solved = true; if (extensive) { if (j < lastDepth) lastDepth = j; } } else { if (solved) { if (!extensive || j > lastDepth || j == height*height-1) { Output(string.Format("Code {0} failed to solve puzzle solved with less powerful solvers.", code)); using (TextWriter writer = File.CreateText("SelfTestOuput" + failCount + "-" + code + ".loop")) { m.Save(writer); } } failCount++; } } } if (solvedByCode) solvedCount++; } m.FullClear(); m.SetRatingCodeOptions("S"); m.Generate(); foreach (string code in codes.Concat(extraCodes)) { m.Clear(); m.SetRatingCodeOptions(code); SolveState result = m.TrySolve(); if (result != SolveState.Solved) { Output(string.Format("Code {0} failed to solve puzzle generated with less powerful generator.", code)); using (TextWriter writer = File.CreateText("SelfTestOuput" + failCount + "-" + code + ".loop")) { m.Save(writer); } failCount++; } } } Output(string.Format("{0} codes solved {1} full generator puzzles {2} times.", codes.Count, extensive ? 100 : 5, solvedCount)); } catch (Exception ex) { if (!(ex is ThreadAbortException)) { Output(string.Format("Failure {0}", ex)); } } }