Esempio n. 1
0
 //------------------------------------------------------------
 // explicit copy
 public void CopyFrom(SuDoKu_Cell other)
 {
     ivValue         = other.ivValue;
     ivCalculated    = other.ivCalculated;
     ivSet           = other.ivSet;
     ivOptions_Count = other.ivOptions_Count;
 }
Esempio n. 2
0
        public void Options_OR(SuDoKu_Cell other)
        {
            uint old = ivValue;

            ivValue |= other.ivValue;
            if (old != ivValue)
            {
                ivOptions_Count = -1;
            }
        }
Esempio n. 3
0
        public void Options_REMOVE(SuDoKu_Cell other)
        {
            uint old = ivValue;

            ivValue &= (~other.ivValue);
            if (old != ivValue)
            {
                ivOptions_Count = -1;
            }
        }
Esempio n. 4
0
        public SuDoKu_Field(SuDoKu_Field other)
        {
            ivDimension = other.ivDimension;
            ivGroupSize = other.ivGroupSize;

            ivCells = new SuDoKu_Cell[ivGroupSize, ivGroupSize];
            for (int row = 0; row < ivGroupSize; row++)
            {
                for (int column = 0; column < ivGroupSize; column++)
                {
                    ivCells[row, column] = new SuDoKu_Cell(other.ivCells[row, column]);
                }
            }
        }
Esempio n. 5
0
        protected int ivGroupSize;                      // the number of fields in a row/column/square

        //************************************************************
        public SuDoKu_Field(int MyDimension)
        {
            ivDimension = MyDimension;
            ivGroupSize = ivDimension * ivDimension;

            ivCells = new SuDoKu_Cell[ivGroupSize, ivGroupSize];
            for (int row = 0; row < ivGroupSize; row++)
            {
                for (int column = 0; column < ivGroupSize; column++)
                {
                    ivCells[row, column] = new SuDoKu_Cell(ivGroupSize);
                }
            }
        }
Esempio n. 6
0
 //------------------------------------------------------------
 // Try to find the correct value for all cell that have
 // only 2 options left
 // return true if the state is still valid
 public bool Solve_Twos()
 {
     for (int row = 0; row < ivGroupSize; ++row)
     {
         for (int column = 0; column < ivGroupSize; column++)
         {
             SuDoKu_Cell c = ivCells[row, column];
             if (!c.isSet && c.Options_Count == 2)
             {
                 SuDoKu_Field old = new SuDoKu_Field(this);
                 int          v   = c.Options_First;
                 set(row, column, v);
                 // if (! Solve_Ones() )
             }
         }
     }
     return(true);
 }
Esempio n. 7
0
        //------------------------------------------------------------
        public void FromString(string Data)
        {
            string[] Fields = Data.Split('\n');
            ivDimension = int.Parse(Fields[0]);
            ivGroupSize = ivDimension * ivDimension;

            ivCells = new SuDoKu_Cell[ivGroupSize, ivGroupSize];

            int i = 0;

            for (int row = 0; row < ivGroupSize; ++row)
            {
                for (int column = 0; column < ivGroupSize; ++column)
                {
                    ivCells[row, column] = new SuDoKu_Cell(Fields[i]);
                    ++i;
                }
            }
        }
Esempio n. 8
0
 //------------------------------------------------------------
 // Set the value for all cells that have only one option less
 // return true if the state is still valid
 public bool Solve_Ones()
 {
     for (int row = 0; row < ivGroupSize; ++row)
     {
         for (int column = 0; column < ivGroupSize; column++)
         {
             SuDoKu_Cell c = ivCells[row, column];
             if (!c.isSet)
             {
                 int v = c.Value;
                 if (v < 0)
                 {
                     return(false);
                 }
                 if (v > 0)
                 {
                     set(row, column, v);
                     return(Solve_Ones());
                 }
             }
         }
     }
     return(true);
 }
Esempio n. 9
0
 //------------------------------------------------------------
 // copy constructor
 public SuDoKu_Cell(SuDoKu_Cell other)
 {
     CopyFrom(other);
 }