Ejemplo n.º 1
0
        private static void Main()
        {
            var pieces = Piece.RealPieces;
            var solver = new SolverUsingDlx(pieces);

            var solutions = solver.FindAllSolutions().ToList();
            solutions = RemoveDuplicateSolutions(solver, solutions);

            var consolePrintTarget = new ConsolePrintTarget();
            var boardPrinter = new BoardPrinter(consolePrintTarget);

            Console.WriteLine("Found {0} solutions", solutions.Count());

            foreach (var solution in solutions)
            {
                var solutionAsArray = solution.ToArray();
                var board = solver.PopulateBoardWithSolution(solutionAsArray);
                Console.WriteLine();
                boardPrinter.Print(board);
                Console.WriteLine();
                solver.WriteSolution(solutionAsArray);
            }

            solver.WritePropertyList("8x8_Pieces1.plist", pieces, solutions);
        }
Ejemplo n.º 2
0
        private static void SolveBoard(int boardSize, Piece[] pieces)
        {
            var board = new Board(boardSize);
            var solver = new Solver();
            var pieceFeeder = new PieceFeeder(pieces);
            var solutionDetails = solver.SolvePuzzle(board, pieceFeeder);

            if (solutionDetails.Solved) {
                var consolePrintTarget = new ConsolePrintTarget();
                var boardPrinter = new BoardPrinter(consolePrintTarget);
                Console.WriteLine("Solution found after {0} iterations.", solutionDetails.Iterations);
                PrintPermutation(solutionDetails.Solution);
                Console.WriteLine();
                boardPrinter.Print(board);
            }
            else
            {
                Console.WriteLine("Failed to find a solution after {0} iterations.", solutionDetails.Iterations);
            }

            Console.WriteLine();
        }