Beispiel #1
0
 private static SolutionTable ConvertToSolutionTable(
     ConstraintSolverSolution solution,
     ZebraPuzzleConstraints constraints)
 {
     return(new SolutionTable(constraints.HouseNumbers.Select(
                                  houseNumber => new SolutionRow
                                  (
                                      houseNumber + 1,
                                      (HouseColour)DetermineTermFromSolution(solution,
                                                                             constraints.ColourMatrix, houseNumber,
                                                                             constraints.HouseNumbers),
                                      (Drink)DetermineTermFromSolution(solution,
                                                                       constraints.DrinkMatrix, houseNumber,
                                                                       constraints.HouseNumbers),
                                      (Nationality)DetermineTermFromSolution(solution,
                                                                             constraints.NationalityMatrix, houseNumber,
                                                                             constraints.HouseNumbers),
                                      (Smoke)DetermineTermFromSolution(solution,
                                                                       constraints.SmokeMatrix, houseNumber,
                                                                       constraints.HouseNumbers),
                                      (Pet)DetermineTermFromSolution(solution,
                                                                     constraints.PetMatrix, houseNumber,
                                                                     constraints.HouseNumbers)
                                  )).ToList()));
 }
Beispiel #2
0
        static void Main()
        {
            var solver      = ConstraintSystem.CreateSolver();
            var constraints = new ZebraPuzzleConstraints(solver);

            solver = AddConstraintsToSolver(solver, constraints);

            var solution      = solver.Solve(new ConstraintSolverParams());
            var solutionTable = ConvertToSolutionTable(solution, constraints);

            WriteZebraSolutionToConsole(solutionTable);
            WriteSolutionForAllTheHousesToConsole(solutionTable);
        }
Beispiel #3
0
        private static ConstraintSystem AddConstraintsToSolver(
            ConstraintSystem solver, ZebraPuzzleConstraints constraints)
        {
            solver.AddConstraints(
                constraints.TheEnglishManLivesInTheRedHouse());
            solver.AddConstraints(
                constraints.TheSwedeHasADog());
            solver.AddConstraints(
                constraints.TheDaneDrinksTea());
            solver.AddConstraints(
                constraints.TheGreenHouseIsImmediatelyLeftOfTheWhiteHouse());
            solver.AddConstraints(
                constraints.TheyDrinkCoffeeInTheGreenHouse());
            solver.AddConstraints(
                constraints.TheManWhoSmokesPallMallHasBirds());
            solver.AddConstraints(
                constraints.InTheYellowHouseTheySmokeDunhill());
            solver.AddConstraints(
                constraints.InTheMiddleHouseTheyDrinkMilk());
            solver.AddConstraints(
                constraints.TheNorwegianLivesInTheFirstHouse());
            solver.AddConstraints(
                constraints.TheManWhoSmokesBlendInHouseNextToHouseWithCats());
            solver.AddConstraints(
                constraints.InHouseNextToHouseWhereHaveAHorseSmokeDunhill());
            solver.AddConstraints(
                constraints.TheManWhoSmokesBlueMasterDrinksBeer());
            solver.AddConstraints(
                constraints.TheGermanSmokesPrince());
            solver.AddConstraints(
                constraints.TheNorwegianLivesNextToTheBlueHouse());
            solver.AddConstraints(
                constraints.TheyDrinkWaterInHouseNextToHouseWhereSmokeBlend());

            return(solver);
        }