protected override AbstractRuleSet CreateRules(bool useDefault) { WireRuleSet wireRuleSet = new WireRuleSet(); QuerySet serialNumberQueries = QuerySet.GetSerialNumberQueries(); QuerySet wireQueries = QuerySet.GetWireQueries(); QuerySet portQueries = QueryablePorts.GetPortQueries(); List <QuerySet> list = new List <QuerySet>(); for (int i = WireSetComponent.MIN_WIRES; i <= WireSetComponent.MAX_WIRES; i++) { List <Rule> list2 = new List <Rule>(); list.Clear(); list.Add(serialNumberQueries); list.Add(wireQueries); if (RuleManager.SeedIsModded) { list.Add(portQueries); } queryPropertyWeights.Clear(); solutionWeights.Clear(); int numRules = GetNumRules(); for (int j = 0; j < numRules; j++) { List <WireColor> listOfWireColors = RuleUtil.GetListOfWireColors(); Rule rule = new Rule(); int numQueriesForRule = GetNumQueriesForRule(); List <WireColor> list3 = new List <WireColor>(); int num = i - 1; for (int k = 0; k < numQueriesForRule; k++) { bool compoundQueriesAllowed = k > 0; List <QueryableProperty> possibleQueryableProperties = CalculatePossibleQueryableProperties(list, num, compoundQueriesAllowed); QueryableProperty queryableProperty = SelectQueryableProperty(possibleQueryableProperties); Query query = new Query(); query.Property = queryableProperty; if (queryableProperty is QueryableWireProperty) { QueryableWireProperty queryableWireProperty = (QueryableWireProperty)queryableProperty; num -= queryableWireProperty.WiresInvolvedInQuery; if (queryableWireProperty.UsesColor) { WireColor wireColor = listOfWireColors[rand.Next(0, listOfWireColors.Count)]; listOfWireColors.Remove(wireColor); query.Args.Add("color", wireColor); if (queryableWireProperty.ColorAvailableForSolution) { list3.Add(wireColor); } } } rule.Queries.Add(query); } List <Solution> possibleSolutions = CalculatePossibleSolutions(i, rule); Solution solution = SelectSolution(possibleSolutions); rule.Solution = solution; if (list3.Count > 0) { rule.SolutionArgs.Add("color", list3[rand.Next(0, list3.Count)]); } if (RuleManager.SeedIsVanilla || IsWireQueryValid(rule)) { list2.Add(rule); } else { j--; //Previous rule was never valid. } } list2 = list2.OrderByDescending(x => x.Queries.Count).ToList(); Rule otherwiseRule = new Rule(); Query otherwiseQuery = new Query { Property = QueryableProperty.Otherwise }; otherwiseRule.Queries.Add(otherwiseQuery); List <Solution> list4 = CalculatePossibleSolutions(i, otherwiseRule); if (RuleManager.SeedIsModded) { list4.Remove(list2.Last().Solution); //Enforce no redundant rules. } otherwiseRule.Solution = list4[rand.Next(0, list4.Count)]; list2.Add(otherwiseRule); wireRuleSet.RulesDictionary[i] = list2; } return(wireRuleSet); }
public WireRuleSet CreateWireRules(int seed) { switch (seed) { case 1: { WireRuleSet wireRuleSet = new WireRuleSet(); wireRuleSet.RulesDictionary[3] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyZeroColorWire } }, Solution = WireSolutions.WireIndex1 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.white } }, Property = QueryableWireProperty.LastWireIsColor } }, Solution = WireSolutions.WireLast }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.blue } }, Property = QueryableWireProperty.MoreThanOneColorWire } }, Solution = WireSolutions.WireColorCutLast, SolutionArgs = new Dictionary <string, object> { { "color", WireColor.blue } } }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireLast } }; wireRuleSet.RulesDictionary[4] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.MoreThanOneColorWire }, new Query { Property = QueryableProperty.IsSerialNumberOdd }, }, Solution = WireSolutions.WireColorCutLast, SolutionArgs = new Dictionary <string, object> { { "color", WireColor.red } } }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.LastWireIsColor }, new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyZeroColorWire }, }, Solution = WireSolutions.WireIndex0 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.blue } }, Property = QueryableWireProperty.IsExactlyOneColorWire } }, Solution = WireSolutions.WireIndex0 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.MoreThanOneColorWire } }, Solution = WireSolutions.WireLast }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireIndex1 } }; wireRuleSet.RulesDictionary[5] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.black } }, Property = QueryableWireProperty.LastWireIsColor }, new Query { Property = QueryableProperty.IsSerialNumberOdd }, }, Solution = WireSolutions.WireIndex3 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyOneColorWire }, new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.MoreThanOneColorWire }, }, Solution = WireSolutions.WireIndex0 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.black } }, Property = QueryableWireProperty.IsExactlyZeroColorWire } }, Solution = WireSolutions.WireIndex1 }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireIndex0 } }; wireRuleSet.RulesDictionary[6] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.IsExactlyZeroColorWire }, new Query { Property = QueryableProperty.IsSerialNumberOdd }, }, Solution = WireSolutions.WireIndex2 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.IsExactlyOneColorWire }, new Query { Args = new Dictionary <string, object>() { { "color", WireColor.white } }, Property = QueryableWireProperty.MoreThanOneColorWire }, }, Solution = WireSolutions.WireIndex3 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyZeroColorWire } }, Solution = WireSolutions.WireLast }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireIndex3 } }; return(wireRuleSet); } case 2: { WireRuleSet wireRuleSet = new WireRuleSet(); wireRuleSet.RulesDictionary[3] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.white } }, Property = QueryableWireProperty.IsExactlyZeroColorWire }, new Query { Property = QueryableProperty.DoesSerialNumberStartWithLetter }, }, Solution = WireSolutions.WireIndex1 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyOneColorWire } }, Solution = WireSolutions.WireIndex0 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.blue } }, Property = QueryableWireProperty.MoreThanOneColorWire } }, Solution = WireSolutions.WireColorCutFirst, SolutionArgs = new Dictionary <string, object> { { "color", WireColor.blue } } }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.LastWireIsColor } }, Solution = WireSolutions.WireLast }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireIndex1 } }; wireRuleSet.RulesDictionary[4] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.IsExactlyOneColorWire }, new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.LastWireIsColor }, }, Solution = WireSolutions.WireIndex2 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.white } }, Property = QueryableWireProperty.LastWireIsColor }, }, Solution = WireSolutions.WireIndex1 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.IsExactlyZeroColorWire } }, Solution = WireSolutions.WireIndex0 }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireLast } }; wireRuleSet.RulesDictionary[5] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.black } }, Property = QueryableWireProperty.MoreThanOneColorWire }, new Query { Property = QueryableProperty.DoesSerialNumberStartWithLetter }, }, Solution = WireSolutions.WireIndex1 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.blue } }, Property = QueryableWireProperty.LastWireIsColor }, new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyOneColorWire }, }, Solution = WireSolutions.WireIndex0 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.LastWireIsColor }, }, Solution = WireSolutions.WireIndex3 }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyZeroColorWire } }, Solution = WireSolutions.WireIndex2 }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireIndex0 } }; wireRuleSet.RulesDictionary[6] = new List <Rule> { new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.IsExactlyOneColorWire }, }, Solution = WireSolutions.WireColorExactlyOne, SolutionArgs = new Dictionary <string, object> { { "color", WireColor.red } } }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.red } }, Property = QueryableWireProperty.LastWireIsColor }, }, Solution = WireSolutions.WireLast }, new Rule { Queries = new List <Query> { new Query { Args = new Dictionary <string, object>() { { "color", WireColor.yellow } }, Property = QueryableWireProperty.IsExactlyZeroColorWire } }, Solution = WireSolutions.WireIndex3 }, new Rule { Queries = new List <Query> { new Query { Property = QueryableProperty.Otherwise } }, Solution = WireSolutions.WireIndex1 } }; return(wireRuleSet); } default: return((WireRuleSet)GenerateRuleSet(seed)); } }