示例#1
0
文件: MoreClues.cs 项目: ddabb/soduku
        /// <summary>
        /// 简单随机搜索
        /// </summary>
        /// <param name="sodukuString"></param>
        /// <returns></returns>
        private string EasySearch(string sodukuString)
        {
            var matrix         = StaticTools.StringToList(sodukuString);
            var locations      = StaticTools.GetLocations(matrix);
            var otherLocations = StaticTools.allLocations.Except(locations).ToList();
            Dictionary <string, int> sodukumap = new Dictionary <string, int>();

            foreach (var loc in locations)
            {
                var newstr      = StaticTools.SetZero(sodukuString, loc);
                var answerCount = new DanceLink().solution_count(newstr);
                sodukumap.Add(newstr, answerCount);
            }

            var tempResult = "";
            var index      = 1;

            foreach (var newGene in sodukumap)
            {
                //Console.WriteLine("存在多解的提示数  \r\n" + newGene);
                //Console.WriteLine("进展:   " +"处理了"+ index+"条,总数是  "+ sodukumap.Count);
                index     += 1;
                tempResult = newClues(newGene.Key, otherLocations);
            }


            Console.WriteLine("最终提示数表达式为\r\n" + tempResult);


            return(tempResult);
        }
示例#2
0
        private int GetMinCount(string sodukuString, Dictionary <string, int> expressCount, List <int[]> switchList)
        {
            int min = 0;

            if (!expressCount.ContainsKey(sodukuString))
            {
                min = new DanceLink().solution_count(sodukuString);
                expressCount.Add(sodukuString, min);
            }
            else
            {
                min = expressCount[sodukuString];
            }

            int start = 0;
            int end   = 0;

            do
            {
                start = min;


                foreach (var switchListCouple in switchList)
                {
                    var newStr = StaticTools.SwitchLocation(sodukuString, switchListCouple[0], switchListCouple[1]);

                    if (!expressCount.ContainsKey(newStr))
                    {
                        var count = new DanceLink().solution_count(newStr);

                        //Console.WriteLine("newStr  " + newStr + "  " + count);
                        expressCount.Add(newStr, count);
                        if (count != 0 && count < min)
                        {
                            sodukuString = newStr;
                            min          = count;
                            break;
                        }
                    }
                }

                end = min;
            } while (start != end);

            return(min);
        }
示例#3
0
文件: MoreClues.cs 项目: ddabb/soduku
        private string newClues(string clues, IEnumerable <int> otherLocations)
        {
            var oneAnswer = new DanceLink().GetOneAnswer(clues);

            //Console.WriteLine("局部结果   " + oneAnswer);
            var locations = StaticTools.GetLocations(clues);

            var otherLocationList
                = otherLocations.ToList();
            //Console.WriteLine("剩余元素个数   " + otherLocations.Count());
            var exceptList = ExceptOtherPearlGene(otherLocationList, locations, oneAnswer);
            //Console.WriteLine("不能填数据的位置为   " +JsonConvert.SerializeObject(exceptList));
            var pure = otherLocations.Except(exceptList);

            var result = GetPureGene(oneAnswer, clues, pure);


            return(result);
        }