/// <summary> /// 暴力搜索 /// </summary> /// <param name="sodukuString"></param> /// <returns></returns> private string ForceSearch(string sodukuString) { var list = StaticTools.GetSubString(sodukuString); var index = 1; foreach (var subString in list) { Console.WriteLine("处理字符串 " + index + " " + subString); index += 1; var market = new SudokuMarket(subString); var result = market.GetCellInfos().Where(c => c.Value.Value == 0). Select(c1 => c1.Value).ToList(); Dictionary <int, List <int> > locationRest = new Dictionary <int, List <int> >(); foreach (var cell in result) { locationRest.Add(cell.location, cell.initrest); } var locationcombine = PermutationAndCombination <int> .GetCombination(locationRest.Keys.ToArray(), 2); foreach (var combine in locationcombine) { var location1 = combine[0]; var location2 = combine[1]; var rest1 = locationRest[location1]; var rest2 = locationRest[location2]; foreach (var value1 in rest1) { Dictionary <int, string> one = new Dictionary <int, string> { { location1, "" + value1 } }; if (new DanceLink().solution_count(StaticTools.SetValues(sodukuString, one)) > 0) { foreach (var value2 in rest2) { Dictionary <int, string> two = new Dictionary <int, string> { { location1, "" + value1 }, { location2, "" + value2 } }; var result1 = StaticTools.SetValues(sodukuString, two); if (StaticTools.IsPearl(result1)) { string dir = AppDomain.CurrentDomain.BaseDirectory; var noticeCount = StaticTools.GetLocations(result1).Count; string configName = Path.Combine(dir, "提示数个数" + noticeCount + "生成于" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"); File.WriteAllText(configName, result1); Console.WriteLine("当前表达式为:" + result1 + "提示数个数为:" + noticeCount); return(result1); } } } } } } return(""); }