// Chronological backtracking algorithm
        static private Tuple <Sudoku, int> ChronologicalBacktracking(Sudoku sudoku)
        {
            // Counting the amount of expansions
            int            expansionCount = 0;
            Stack <Sudoku> stack          = new Stack <Sudoku>();

            // Initial push
            stack.Push(sudoku);
            Sudoku newSudoku = sudoku.Clone();

            while (!sudoku.IsSolution())
            {
                newSudoku = sudoku.Clone();

                // Get new variable, the first empty one
                Tuple <int, int> newVariable = newSudoku.EmptyVariable(0);
                List <int>       domain      = newSudoku.domains[newVariable.Item1, newVariable.Item2];

                newSudoku[newVariable.Item1, newVariable.Item2] = domain[sudoku.domainCounter];

                // Check if the new sudoku is a partial solution, if so, push to stack
                if (newSudoku.IsPartialSolution(newVariable))
                {
                    stack.Push(newSudoku);
                }

                // Domain and expansion counter
                sudoku.domainCounter++;
                expansionCount++;

                // Backtrack step
                if (sudoku.domainCounter >= domain.Count)
                {
                    sudoku = stack.Pop();
                }
            }
            return(new Tuple <Sudoku, int>(sudoku, expansionCount));
        }
        // Forward checking algorithm
        static private Tuple <Sudoku, int> ForwardChecking(Sudoku sudoku)
        {
            int            expansionCount = 0;
            Stack <Sudoku> stack          = new Stack <Sudoku>();

            stack.Push(sudoku);
            Sudoku newSudoku = sudoku.Clone();

            while (!sudoku.IsSolution())
            {
                newSudoku = sudoku.Clone();
                bool alreadyPopped = false;

                // Generate and push successor
                Tuple <int, int> newVariable = newSudoku.EmptyVariable(0);
                List <int>       domain      = newSudoku.domains[newVariable.Item1, newVariable.Item2];

                newSudoku[newVariable.Item1, newVariable.Item2] = domain[sudoku.domainCounter];

                if (newSudoku.IsPartialSolution(newVariable))
                {
                    stack.Push(newSudoku);
                }

                // Domain counter goes up
                sudoku.domainCounter++;
                expansionCount++;

                /*
                 * Update constraints where this sudoku is a part of.
                 * Find all constraints that should be updated and update them
                 * check all constraints in constraintset.
                 * If V_i has value, get all constraints C_ji where V_j not instantiated, and make them consistent.
                 */
                foreach (Tuple <Tuple <int, int>, Tuple <int, int> > constraint in newSudoku.constraintSet)
                {
                    if (constraint.Item2.Equals(newVariable))
                    {
                        // If V_j is not fixed (not instantiated)

                        if (!newSudoku.fixedNumbers.Contains(new Tuple <int, int>(constraint.Item1.Item1, constraint.Item1.Item2)))
                        {
                            // Remove the value of V_i from domains of V_j
                            newSudoku.domains[constraint.Item1.Item1, constraint.Item1.Item2].Remove(domain[newSudoku.domainCounter]);

                            // If new domain of a location is empty, it should step back.
                            // Problem with double backtrack step (if also sudoku.domaincounter >= domain.count), therefor we added extra check at backtrack step
                            if (newSudoku.domains[constraint.Item1.Item1, constraint.Item1.Item2].Count == 0)
                            {
                                // Get previous sudoku
                                sudoku = stack.Pop();
                                Console.WriteLine("empty domain, step back to previous sudoku");
                                // Set alreadyPopped to true, so we don't pop twice.
                                alreadyPopped = true;
                                break;
                            }
                        }
                    }
                }

                // Backtrack step (make sure stack isn't popped yet)
                if (sudoku.domainCounter >= domain.Count && alreadyPopped == false)
                {
                    sudoku = stack.Pop();
                    Console.WriteLine("backtrack-step");
                }
            }
            return(new Tuple <Sudoku, int>(sudoku, expansionCount));
        }