コード例 #1
0
        public List <RangeItem> GetRange(RangeType type, int index)
        {
            var result = new List <RangeItem>();
            int aBegin = 0;
            int aEnd   = 0;
            int bBegin = 0;
            int bEnd   = 0;

            switch (type)
            {
            case RangeType.Row:
                aBegin = index;
                aEnd   = index + 1;
                bBegin = 0;
                bEnd   = 9;
                break;

            case RangeType.Column:
                aBegin = 0;
                aEnd   = 9;
                bBegin = index;
                bEnd   = index + 1;
                break;

            case RangeType.Block:

                var firstBlockIndex = new int[9] {
                    0, 0, 0, 3, 3, 3, 6, 6, 6
                };

                aBegin = firstBlockIndex[index];
                aEnd   = firstBlockIndex[index] + 3;
                bBegin = (index - firstBlockIndex[index]) * 3;
                bEnd   = bBegin + 3;

                break;
            }

            for (int i = aBegin; i < aEnd; i++)
            {
                for (int j = bBegin; j < bEnd; j++)
                {
                    result.Add(RangeItems.Find(o => o.Row == i && o.Column == j));
                }
            }

            return(result);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            RangeItems ris = new RangeItems(14, 54); // create with range
            float fLimit = 96f; // let's test with 96%

            Parallel.For(0, ris.Count, i => { ris[i].Compute(fLimit); }); // compute them all

            // pump to CSV
            File.WriteAllText("results.csv", ris.BuildCSVHeader());
            foreach (RangeItem ri in ris)
                File.AppendAllText("results.csv", ri.ToCSVString());

            // the end
            Console.Write("Finished.. press enter: ");
            Console.ReadLine();
        }
コード例 #3
0
        public bool TryResolve(int row, int column)
        {
            var item       = RangeItems.Find(o => o.Row == row && o.Column == column);
            var logMessage = $"Try resolve [{item.Row}, {item.Column}]";

            if (item.PossibleValues.Count == 1)
            {
                item.Value                    = item.PossibleValues[0];
                item.PossibleValues           = new List <int>();
                Sudoku[item.Row, item.Column] = item.Value;

                logMessage += $" -> Resolved: {Sudoku[item.Row, item.Column]}";
                Log(logMessage);
                return(true);
            }

            logMessage += $" -> Not Resolved. Possible values: [{string.Join(", ", item.PossibleValues)}]";
            Log(logMessage);
            return(false);
        }
コード例 #4
0
 public List <RangeItem> GetAllBlank()
 {
     return(RangeItems.FindAll(i => i.Value == 0));
 }