Example #1
0
        /// <summary>
        /// 解答题目
        /// </summary>
        /// <param name="doString">数独字符串</param>
        /// <returns></returns>
        public static int[] Solve(string doString)
        {
            int       r  = 0;
            int       c  = 0;
            SuDoTable dt = new SuDoTable();

            for (int i = 0; i < 81; i++)
            {
                r        = i / 9;
                c        = i % 9;
                dt[r, c] = new SuDoCell(r, c);
            }
            int[] doArray = SuDoHelper.GetDoIntArrary(doString);
            for (int i = 0; i < doArray.Length; i++)
            {
                r = i / 9;
                c = i % 9;
                int value = doArray[i];
                dt.SetValue(r, c, value);//值先进行校验后,保存入DoTabel
            }
            dt.Solve();
            List <int> intList = new List <int>();

            for (int i = 0; i < dt._DoTable.Length; i++)
            {
                intList.Add(dt._DoTable[i / 9, i % 9].Value);
            }
            return(intList.ToArray());
        }
Example #2
0
        public SudoExercise(string createrEmail, string playerEmail, string doExercise)
        {
            this.ID             = Guid.NewGuid().ToString("N");
            this.CreaterEmail   = createrEmail;
            this.PlayerEmail    = playerEmail;
            this.SingleExercise = doExercise;
            int[]         solution = SuDoTable.Solve(doExercise);
            StringBuilder sb       = new StringBuilder();

            foreach (var item in solution)
            {
                sb.Append(item);
            }
            this.Solution      = sb.ToString();
            this.SolveDuration = DateTime.Parse("00:00:00");
            this.SolveTime     = 0;
        }