/// <summary> /// Initializes a new instance of the <see cref="MultiRuleSet"/> class, using multiple rules. /// <remarks>All of the rules are possible, but only one is the right one.</remarks> /// </summary> /// <param name="rule">The rule, which contains two houses.</param> /// <param name="mathRule">The math rule, which implements the arithmetical relations between the houses.</param> /// <exception cref="ArgumentException">Thrown, when the rule.Houses.Count != 2.</exception> public MultiRuleSet(Rule rule, MathRule mathRule) { if (rule.Houses.Count != 2) { throw new ArgumentException("The rule houses count must be 2!"); } this.rule = rule; this.mathRule = mathRule; }
/// <summary> /// Creates internal list of 15 quiz rules. /// </summary> /// <returns>The quiz rules.</returns> private List <IRuleSet> CreateRules() { // Rule 1: The Englishman lives at the red house var ruleSet1 = new SingleRuleSet(new Rule(new House() { Nationality = Nationality.Englishman, Color = Color.Red })); // Rule 2: The Swedish has a dog var ruleSet2 = new SingleRuleSet(new Rule(new House() { Nationality = Nationality.Swedish, Pet = Pet.Dog })); // Rule 3: The Danish drinks tea var ruleSet3 = new SingleRuleSet(new Rule(new House() { Nationality = Nationality.Danish, Drink = Drink.Tea })); // Rule 4: The green house is at the left side of the white house var rule4a = new Rule( new House() { Color = Color.Green }, new House() { Color = Color.White }); var rule4b = new MathRule(House.MinHouseNumber, House.MaxHouseNumber, MathOperation.SmallerThan, typeof(House), "Number"); var ruleSet4 = new MultiRuleSet(rule4a, rule4b); // Rule 5: The Norwegian lives at the first house var ruleSet5 = new SingleRuleSet(new Rule(new House() { Nationality = Nationality.Norwegian, Number = 1 })); // Rule 6: The green house owner drinks coffee var ruleSet6 = new SingleRuleSet(new Rule(new House() { Color = Color.Green, Drink = Drink.Coffee })); // Rule 7: The man who smokes Pall Mall has a bird var ruleSet7 = new SingleRuleSet(new Rule(new House() { Cigarettes = Cigarettes.PallMall, Pet = Pet.Bird })); // Rule 8: The middle house owner drinks milk var ruleSet8 = new SingleRuleSet(new Rule(new House() { Number = 3, Drink = Drink.Milk })); // Rule 9: The yellow house owner smokes Dunhill var ruleSet9 = new SingleRuleSet(new Rule(new House() { Color = Color.Yellow, Cigarettes = Cigarettes.Dunhill })); // Rule 10: The Marlboro smoker has neighbour, which has Cat var rule10 = new Rule( new House() { Cigarettes = Cigarettes.Marlboro }, new House() { Pet = Pet.Cat }); var ruleSet10 = new SingleRuleSet(rule10); // Rule 11: The man who has horse has neighbour, which smokes Dunhill var rule11 = new Rule( new House() { Pet = Pet.Horse }, new House() { Cigarettes = Cigarettes.Dunhill }); var ruleSet11 = new SingleRuleSet(rule11); // Rule 12: The Winfield smoker drinks beer var ruleSet12 = new SingleRuleSet(new Rule(new House() { Cigarettes = Cigarettes.Winfield, Drink = Drink.Beer })); // Rule 13: The Norwegian lives next to the blue house var rule13 = new Rule( new House() { Nationality = Nationality.Norwegian }, new House() { Color = Color.Blue }); var ruleSet13 = new SingleRuleSet(rule13); // Rule 14: The German smokes Rothmans var ruleSet14 = new SingleRuleSet(new Rule(new House() { Nationality = Nationality.German, Cigarettes = Cigarettes.Rothmans })); // Rule 15: The Marlboro smoker has neighbour, which drinks water var rule15 = new Rule( new House() { Cigarettes = Cigarettes.Marlboro }, new House() { Drink = Drink.Water }); var ruleSet15 = new SingleRuleSet(rule15); var ruleSets = new List <IRuleSet>() { ruleSet1, ruleSet2, ruleSet3, ruleSet4, ruleSet5, ruleSet6, ruleSet7, ruleSet8, ruleSet9, ruleSet10, ruleSet11, ruleSet12, ruleSet13, ruleSet14, ruleSet15 }; return(ruleSets); }