Exemplo n.º 1
0
        public int[,] FillFieldsonColumns(int[,] array, Possibilities possibilities)

        {
            int sum = 0;

            int[] coords = { 0, 0 };
            var   value  = possibilities.Values;

            for (int i = 0; i < value.GetLength(0); i++)
            {
                for (int j = 0; j < value.GetLength(1); j++)
                {
                    if (value[j, i] == 1)
                    {
                        coords[0] = j;
                        coords[1] = i;
                        sum++;
                    }
                }
                if (sum == 1)
                {
                    array[coords[0], coords[1]] = possibilities.Number;
                    break;
                }
                sum = 0;
            }
            return(array);
        }
Exemplo n.º 2
0
 public Sudokunumber(int nr) : this()
 {
     this.Number        = nr;
     Possibilitiesarray = new Possibilities(nr);
 }
Exemplo n.º 3
0
        public void PossibilityFinder(int[,] array, Sudokunumber number)
        {
            Possibilities Possibilitiesarray = new Possibilities(number.Number);
            var           row    = array.GetLength(0);
            var           column = array.GetLength(1);

            for (int i = 0; i < row; i++)
            {
                for (int f = 0; f < column; f++)
                {
                    if (array[i, f] > 0)
                    {
                        Possibilitiesarray.Values[i, f] = 0;
                    }
                    else
                    {
                        bool ispresent = false;
                        foreach (var nr in number.Rows.Find(x => x.Number == i + 1).Values)
                        {
                            if (nr == number.Number)
                            {
                                ispresent = true;
                                break;
                            }
                        }

                        if (!ispresent)
                        {
                            foreach (var nr in number.Columns.Find(x => x.Number == f + 1).Values)
                            {
                                if (nr == number.Number)
                                {
                                    ispresent = true;
                                    break;
                                }
                            }
                            if (!ispresent)
                            {
                                #region (decide fieldnumber)
                                int fieldnumber;
                                if (f < 3)
                                {
                                    if (i < 3)
                                    {
                                        fieldnumber = 1;
                                    }
                                    else if (i > 5)
                                    {
                                        fieldnumber = 7;
                                    }
                                    else
                                    {
                                        fieldnumber = 4;
                                    }
                                }

                                else if (f > 5)
                                {
                                    if (i < 3)
                                    {
                                        fieldnumber = 3;
                                    }
                                    else if (i > 5)
                                    {
                                        fieldnumber = 9;
                                    }
                                    else
                                    {
                                        fieldnumber = 6;
                                    }
                                }

                                else
                                if (i < 3)
                                {
                                    fieldnumber = 2;
                                }
                                else if (i > 5)
                                {
                                    fieldnumber = 8;
                                }
                                else
                                {
                                    fieldnumber = 5;
                                }
                                #endregion

                                foreach (var nr in number.Fields.Find(x => x.Number == fieldnumber).Values)
                                {
                                    if (nr == number.Number)
                                    {
                                        ispresent = true;
                                        break;
                                    }
                                }
                            }
                        }

                        if (ispresent)
                        {
                            Possibilitiesarray.Values[i, f] = 0;
                        }
                        else
                        {
                            Possibilitiesarray.Values[i, f] = 1;
                        }
                    }
                }
            }
            number.Possibilitiesarray = Possibilitiesarray;
        }
Exemplo n.º 4
0
        public int[,] FillFieldsonFields(int[,] array, Possibilities possibilities)

        {
            int rows    = 0;
            int columns = 0;
            int sum     = 0;

            int[] coords = { 0, 0 };
            var   value  = possibilities.Values;

            for (int k = 0; k < 9; k++)
            {
                switch (k)
                {
                case 0:
                    rows    = 0;
                    columns = 0;
                    break;

                case 1:
                    rows    = 0;
                    columns = 3;
                    break;

                case 2:
                    rows    = 0;
                    columns = 6;
                    break;

                case 3:
                    rows    = 3;
                    columns = 0;
                    break;

                case 4:
                    rows    = 3;
                    columns = 3;
                    break;

                case 5:
                    rows    = 3;
                    columns = 6;
                    break;

                case 6:
                    rows    = 6;
                    columns = 0;
                    break;

                case 7:
                    rows    = 6;
                    columns = 3;
                    break;

                case 8:
                    rows    = 6;
                    columns = 6;
                    break;
                }

                for (int j = 0; j < 3; j++)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (value[i + rows, j + columns] == 1)
                        {
                            coords[0] = i + rows;
                            coords[1] = j + columns;
                            sum++;
                        }
                    }
                }
                if (sum == 1)
                {
                    array[coords[0], coords[1]] = possibilities.Number;
                    break;
                }
                sum = 0;
            }
            return(array);
        }