예제 #1
0
파일: MoreClues.cs 프로젝트: ddabb/soduku
        /// <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("");
        }
예제 #2
0
        /// <summary>
        /// 刷新面板
        /// </summary>
        private void RefreshPanel()
        {
            var config = _config.ColorConfig;

            this.BackColor = config.FrmColor;
            if (currentMarket == null)
            {
                return;
            }

            UpdateCurrentSudokuInfo();
            Dictionary <string, CellInfo> cells = currentMarket.GetCellInfos();

            this.BackColor = _config.ColorConfig.FrmColor;
            this.tableLayoutPanel1.SuspendLayout();
            foreach (KeyValuePair <string, CellInfo> kv in cells)
            {
                var      location = kv.Key;
                CellInfo cell     = kv.Value;
                var      clue     = locationClues[location];
                var      text     = TextBoxdic[location];
                text.Text = "";
                clue.SetColors(_config);
                if (cell.Value != 0)
                {
                    text.Visible   = true;
                    clue.Visible   = false;
                    text.Text      = "" + cell.Value;
                    text.ForeColor = cell.isInit ? config.QuestionForeColor : config.AnswerForeColor;
                }
                else
                {
                    clue.SetClues(cell.initrest);
                    clue.Visible = showhelp;
                    text.Visible = !showhelp;
                }
            }
            this.tableLayoutPanel1.ResumeLayout();
        }
예제 #3
0
파일: Program.cs 프로젝트: ddabb/soduku
        static void Main(string[] args)

        {
            if (1 > 0)
            {
                SudokuMarket sdm =
                    new SudokuMarket(soduku39);
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("from sympy import *");
                var cells = sdm.GetCellInfos().Values.ToList();
                foreach (var cell in cells)
                {
                    sb.AppendLine(string.Format("{0}= Symbol('{0}')", cell.variablename));
                }

                sb.AppendLine("print(solve([");

                for (int index = 0; index < 9; index++)
                {
                    var index1 = index;
                    AppendCondition1(cells, c => c.row == index1, sb);
                    AppendCondition1(cells, c => c.column == index1, sb);
                    AppendCondition1(cells, c => c.block == index1, sb);
                    AppendCondition2(cells, c => c.row == index1, sb);
                    AppendCondition2(cells, c => c.column == index1, sb);
                    AppendCondition2(cells, c => c.block == index1, sb);
                }

                var valuedCells = cells.Where(c => c.Value != 0);
                foreach (var cellInfo in valuedCells)
                {
                    sb.AppendLine(string.Format("    {0}{1},", cellInfo.variablename, GetCountValue(cellInfo)));
                }

                sb.AppendLine("     1-1");//消除逗号的影响
                sb.AppendLine(string.Format("],[{0}]))", string.Join(",", cells.Select(c => c.variablename))));


                File.WriteAllText("solveSudoku.py", sb.ToString());
                File.WriteAllText("solveSudoku.begintime.txt", DateTime.Now.ToString());
                Console.WriteLine("开始计算");
                string result = runPython("solveSudoku.py", "");

                File.WriteAllText("solveSudoku.endtime.txt", DateTime.Now.ToString());
                File.WriteAllText("solveSudoku.result", result);
                Console.WriteLine(result);
                Console.WriteLine("运算结束");
                Console.ReadKey();


                var breakin = 0;
            }
            else
            {
                var c1111 = new SudokuMarket(new SudokuBuilder().MakeSudoku()).Pearl.StrExpress;


                var testString =
                    "705602000640305100100000300200000000000000000000004269000000000010040980000098412"; //29个提示数的珍珠盘
                //testString = c1111;
                var test = StaticTools.IsPearl(testString);
                Console.WriteLine("    当前表达式是\r\n" + testString + "\r\n" + StaticTools.GetLocations(testString).Count);
                Console.WriteLine("输入数据的提示数个数为" + StaticTools.GetLocations(testString).Count);
                var c = new MoreClues().GetMoreNotice(testString, 39
                                                      ); //26个提示数

                Console.WriteLine(c);
                Console.ReadKey();
                Console.ReadKey();
                Console.ReadKey();
                Console.ReadKey();
            }


            Console.ReadKey();
            return;
        }