// Method for cloning a sudoku grid
        public Sudoku_Grid Clone(Sudoku_Grid other)
        {
            // Make a new grid
            Sudoku_Grid returnClone = new Sudoku_Grid();

            returnClone.currentVariableIndex = 0;

            // Go through the sudoku grid that needs to be copied
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    // Make a new square, because we don't want to point to the old square
                    Square temp = new Square();
                    temp.variables = new List <int>();
                    // Add all the variables of the domain in the variables list of the new square
                    if (other.sudoku[i, j].variables != null)
                    {
                        foreach (int x in other.sudoku[i, j].variables)
                        {
                            temp.variables.Add(x);
                        }
                    }
                    // Copy all the other membervariables
                    temp.row        = other.sudoku[i, j].row;
                    temp.column     = other.sudoku[i, j].column;
                    temp.number     = other.sudoku[i, j].number;
                    temp.domainSize = other.sudoku[i, j].domainSize;
                    // Assign the square to the location in the grid
                    returnClone.sudoku[i, j] = temp;
                }
            }

            return(returnClone);
        }
 // Initialise the forward checking algorithm
 static void initialise_forwardchecking()
 {
     starttime = DateTime.Now;
     // Make a new grid
     currentGrid = new Sudoku_Grid();
     // Add squares to the grid with their number, row and column
     for (int i = 0; i < N; i++)
     {
         for (int j = 0; j < N; j++)
         {
             currentGrid.sudoku[i, j]        = new Square();
             currentGrid.sudoku[i, j].row    = i;
             currentGrid.sudoku[i, j].column = j;
             currentGrid.sudoku[i, j].number = sudoku[i, j];
             // Make a domain list of all the possible numbers a square can have if it is changeable
             if (!unchangable[i, j])
             {
                 currentGrid.sudoku[i, j].variables = new List <int>();
                 int size = 0;
                 for (int k = 1; k <= N; k++)
                 {
                     sudoku[i, j] = k;
                     if (!Violation(i, j))
                     {
                         currentGrid.sudoku[i, j].variables.Add(k);
                         size++;
                     }
                 }
                 // Reset the value
                 sudoku[i, j] = 0;
                 currentGrid.sudoku[i, j].domainSize = size;
             }
         }
     }
     currentGrid.ForwardCheck();
 }
        // Recursive backtracking method that uses forward checking with the most constraining variable
        public void ForwardCheck()
        {
            // Check if the most constraining variable is empty
            if (MCV == null)
            {
                // Create a new location with a high domain size
                Location l = new Location();
                l.size = 900;

                //Check for each square in the sudoku which square has the lowest domainsize
                foreach (Square s in sudoku)
                {
                    if (!Program.unchangable[s.row, s.column])
                    {
                        if (s.domainSize <= l.size)
                        {
                            l.row    = s.row;
                            l.column = s.column;
                            l.size   = s.domainSize;
                            if (l.size == 1)
                            {
                                break;
                            }
                        }
                    }
                }
                // Assign the location to the most contraining variable
                MCV = l;
            }

            // If the most constraining variable has a size of 900, the sudoku is solved and print the solution
            if (MCV.size > 800)
            {
                //PrintSolution();
                Program.sudokufc = sudoku;
                Printer.print_sudoku();
                return;
            }
            Program.recursivecalls++;
            // Copy this grid to make changes in the child
            child        = new Sudoku_Grid();
            child        = Clone(this);
            child.parent = this;

            // Get location of most constraining square
            int row = MCV.row;
            int col = MCV.column;

            // Check if index has exceeded the amount of variables there are
            if (currentVariableIndex < sudoku[row, col].variables.Count)
            {
                int variable = sudoku[row, col].variables[currentVariableIndex];
                // Set the square to this variable
                child.sudoku[row, col].number = variable;

                // If there are no empty domains move next with the child
                if (child.MakeConsistent(row, col))
                {
                    child.ForwardCheck();
                }
                // Else increase the variable index to try the next possible variable
                else
                {
                    currentVariableIndex++;
                    ForwardCheck();
                }
            }
            // If it has exceeded the amount of variables go back to the parent
            else
            {
                parent.currentVariableIndex++;
                parent.ForwardCheck();
            }
        }