Esempio n. 1
0
        public void CompileStructPartyGeneratorTest()
        {
            var d     = new CompiledStructType(typeof(Character));
            var prog  = new Problem("compiled struct party generator");
            var party = new[] { "fred", "jenny", "sally" };

            // Make one for each party member
            var partyVars = party.Select(c => (Character)prog.Instantiate(c, d)).ToArray();

            // All the classes have to be different
            prog.AllDifferent(partyVars.Select(c => c.Class));

            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(prog.Solve().Model);
            }
        }
Esempio n. 2
0
        public void StructPartyGeneratorTest()
        {
            var prog  = new Problem("Struct character generator");
            var party = new[] { "fred", "jenny", "sally" };

            var characterType = new Struct("Character",
                                           // Members
                                           new[] {
                new Member("race", null, "human", "electroid", "insectoid"),
                new Member("class", null, "fighter", "magic user", "cleric", "thief"),
                new Member("nationality", "race=human", "landia", "placeville", "cityburgh"),
                new Member("religion", "class=cleric", "monotheist", "pantheist", "lovecraftian", "dawkinsian")
            },
                                           // Constraint
                                           (p, v) =>
            {
                // Electroids are atheists
                p.Inconsistent(v["race"] == "electroid", v["class"] == "cleric");
                // Lovecraftianism is outlawed in Landia
                p.Inconsistent(v["nationality"] == "landia", v["religion"] == "lovecraftian");
                // Insectoids believe in strict hierarchies
                p.Inconsistent(v["race"] == "insectoid", v["religion"] == "pantheist");
                // Lovecraftianism is the state religion of cityburgh
                p.Inconsistent(v["nationality"] == "cityburgh", v["class"] == "cleric", v["religion"] != "lovecraftian");
            });

            // Make one for each party member
            var castVars = party.Select(c => (StructVar)prog.Instantiate(c, characterType)).ToArray();

            // All the classes have to be different
            prog.AllDifferent(castVars.Select(c => (FDVariable <string>)c["class"]));
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(prog.Solve().Model);
            }
        }