public static void Solve(EightQueenPartialSolution sol)
        {
            int exam = sol.Examine();

            if (exam == EightQueenPartialSolution.ACCEPT)
            {
                Console.WriteLine(sol);
            }
            else if (exam != EightQueenPartialSolution.ABANDON)
            {
                foreach (EightQueenPartialSolution p in sol.Extend())
                {
                    Solve(p);
                }
            }
        }
Exemple #2
0
    public EightQueenPartialSolution[] Extend()
    {
        // Generate a new solution for each column.
        EightQueenPartialSolution[] result = new EightQueenPartialSolution[NQUEENS];
        for (int i = 0; i < result.Length; i++)
        {
            int size = queens.Length;

            // The new solution has one more queen (on the next higher row) than this one.
            result[i] = new EightQueenPartialSolution(size + 1);

            // Copy this solution into the new one.
            for (int j = 0; j < size; j++)
            {
                result[i].queens[j] = queens[j];
            }

            // Append the new queen into the ith column.
            result[i].queens[size] = new Queen(size, i);
        }
        return(result);
    }