Esempio n. 1
0
 public bool HasNumber(SudoNum value)
 {
     if (value == SudoNum.Unknown)
     {
         throw new InvalidOperationException();
     }
     return(nums[(int)value]);
 }
Esempio n. 2
0
        public static bool Filler(ref Panel pl)
        {
            bool changed = false;

            //check blocks
            for (int y = 0; y < 9; y++)
            {
                for (int x = 0; x < 9; x++)
                {
                    if (pl[x, y].Number == SudoNum.Unknown && pl[x, y].CandidateNumber.Count == 1)
                    {
                        SudoNum tmp = pl[x, y].CandidateNumber.GetNumbers()[0];
                        pl[x, y].Number = tmp;
                        RowExpel(ref pl, y, x, tmp);
                        ColumnExpel(ref pl, x, y, tmp);
                        RegionExpel(ref pl, Panel.GetRegion(x, y), Panel.GetRegionNumber(x, y), tmp);
                        changed = true;
                    }
                }
            }
            //check regions
            for (int r = 0; r < 9; r++)
            {
                int[] counter = new int[10];
                for (int n = 0; n < 9; n++)
                {
                    if (pl[Panel.GetX(r, n), Panel.GetY(r, n)].Number != SudoNum.Unknown)
                    {
                        continue;
                    }
                    foreach (SudoNum item in pl[Panel.GetX(r, n), Panel.GetY(r, n)].CandidateNumber.GetNumbers())
                    {
                        counter[(int)item]++;
                    }
                }
                for (int i = 1; i < 10; i++)
                {
                    if (counter[i] == 1)
                    {
                        for (int n = 0; n < 9; n++)
                        {
                            if (pl[Panel.GetX(r, n), Panel.GetY(r, n)].CandidateNumber.HasNumber((SudoNum)i))
                            {
                                pl[Panel.GetX(r, n), Panel.GetY(r, n)].Number = (SudoNum)i;
                                RowExpel(ref pl, Panel.GetY(r, n), Panel.GetX(r, n), (SudoNum)i);
                                ColumnExpel(ref pl, Panel.GetX(r, n), Panel.GetY(r, n), (SudoNum)i);
                                changed = true;
                            }
                        }
                    }
                }
            }
            return(changed);
        }
Esempio n. 3
0
 public static void RegionExpel(ref Panel pl, int region, int except, SudoNum value)
 {
     for (int i = 0; i < 9; i++)
     {
         if (i == except)
         {
             continue;
         }
         pl[Panel.GetX(region, i), Panel.GetY(region, i)].CandidateNumber.Remove(value);
     }
 }
Esempio n. 4
0
 public static void ColumnExpel(ref Panel pl, int column, int except, SudoNum value)
 {
     for (int i = 0; i < 9; i++)
     {
         if (i == except)
         {
             continue;
         }
         pl[column, i].CandidateNumber.Remove(value);
     }
 }
Esempio n. 5
0
 public static void RowExpel(ref Panel pl, int row, int except, SudoNum value)
 {
     for (int i = 0; i < 9; i++)
     {
         if (i == except)
         {
             continue;
         }
         pl[i, row].CandidateNumber.Remove(value);
     }
 }
Esempio n. 6
0
        public SudoNum[] GetNumbers()
        {
            SudoNum[] n = new SudoNum[Count];
            int       s = 0;

            for (int i = 1; i < 10; i++)
            {
                if (nums[i])
                {
                    n[s] = (SudoNum)i;
                    s++;
                }
            }
            return(n);
        }
Esempio n. 7
0
 public Block(SudoNum number, bool stable, Candidate cand) : this(number, stable)
 {
     this.cand = cand;
 }
Esempio n. 8
0
 public Block(SudoNum number, bool stable) : this(number)
 {
     Stable = stable;
 }
Esempio n. 9
0
 public Block(SudoNum number) : this()
 {
     Number = number;
 }
Esempio n. 10
0
 public void Remove(SudoNum n)
 {
     nums[(int)n] = false;
 }
Esempio n. 11
0
 public void Add(SudoNum n)
 {
     nums[(int)n] = true;
 }