Example #1
0
        public void LowTechCharacterGeneratorTest()
        {
            var prog = new Problem("Character generator");

            prog.Assert("character");

            // Races
            Partition("character", "human", "electroid", "insectoid");

            // Classes
            Partition("character", "fighter", "magic user", "cleric", "thief");
            prog.Inconsistent("electroid", "cleric");

            // Nationalities of humans
            Partition("human", "landia", "placeville", "cityburgh");

            // Religions of clerics
            Partition("cleric", "monotheist", "pantheist", "lovecraftian", "dawkinsian");

            // Lovecraftianism is outlawed in Landia
            prog.Inconsistent("landia", "lovecraftian");

            // Insectoids believe in strict hierarchies
            prog.Inconsistent("insectoid", "pantheist");

            // Lovecraftianism is the state religion of cityburgh
            prog.Inconsistent("cityburgh", "cleric", Not("lovecraftian"));

            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(prog.Solve().Model);
            }
        }
Example #2
0
        public void PartyGeneratorTest()
        {
            var prog         = new Problem("Party generator");
            var cast         = new[] { "fred", "jenny", "sally" };
            var character    = Predicate <string>("character");
            var human        = Predicate <string>("human");
            var electroid    = Predicate <string>("electroid");
            var insectoid    = Predicate <string>("insectoid");
            var fighter      = Predicate <string>("fighter");
            var magicUser    = Predicate <string>("magic_user");
            var cleric       = Predicate <string>("cleric");
            var thief        = Predicate <string>("thief");
            var landia       = Predicate <string>("landia");
            var placeville   = Predicate <string>("placeville");
            var cityburgh    = Predicate <string>("cityburgh");
            var monotheist   = Predicate <string>("monotheist");
            var pantheist    = Predicate <string>("pantheist");
            var lovecraftian = Predicate <string>("lovecraftian");
            var dawkinsian   = Predicate <string>("dawkinsian");


            foreach (var who in cast)
            {
                prog.Assert(character(who));
                // Races
                Partition(character(who), human(who), electroid(who), insectoid(who));

                // Classes
                Partition(character(who), fighter(who), magicUser(who), cleric(who), thief(who));
                prog.Inconsistent(electroid(who), cleric(who));

                // Nationalities of humans
                Partition(human(who), landia(who), placeville(who), cityburgh(who));

                // Religions of clerics
                Partition(cleric(who), monotheist(who), pantheist(who), lovecraftian(who), dawkinsian(who));
                // Lovecraftianism is outlawed in Landia
                prog.Inconsistent(landia(who), lovecraftian(who));
                // Insectoids believe in strict hierarchies
                prog.Inconsistent(insectoid(who), pantheist(who));
                // Lovecraftianism is the state religion of cityburgh
                prog.Inconsistent(cityburgh(who), cleric(who), Not(lovecraftian(who)));
            }

            prog.AtMost(1, cast, fighter);
            prog.AtMost(1, cast, magicUser);
            prog.AtMost(1, cast, cleric);
            prog.AtMost(1, cast, thief);


            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(prog.Solve().Model);
            }
        }
Example #3
0
 public CharacterWithEnums(object name, Problem p, Literal condition = null) : base(name, p, condition)
 {
     // Electroids are atheists
     p.Inconsistent(Race == Races.Electroid, Class == Classes.Cleric);
     // Lovecraftianism is outlawed in Landia
     p.Inconsistent(Nationality == Nationalities.Landia, Religion == Religions.Lovecraftian);
     // Insectoids believe in strict hierarchies
     p.Inconsistent(Race == Races.Insectoid, Religion == Religions.Pantheist);
     // Lovecraftianism is the state religion of cityburgh
     p.Inconsistent(Nationality == Nationalities.Cityburgh, Class == Classes.Cleric, Religion != Religions.Lovecraftian);
 }
Example #4
0
 public Character(object name, Problem p, Literal condition = null) : base(name, p, condition)
 {
     // Electroids are atheists
     p.Inconsistent(Race == "electroid", Class == "cleric");
     // Lovecraftianism is outlawed in Landia
     p.Inconsistent(Nationality == "landia", Religion == "lovecraftian");
     // Insectoids believe in strict hierarchies
     p.Inconsistent(Race == "insectoid", Religion == "pantheist");
     // Lovecraftianism is the state religion of cityburgh
     p.Inconsistent(Nationality == "cityburgh", Class == "cleric", Religion != "lovecraftian");
 }
Example #5
0
        public void CharacterGeneratorTest()
        {
            var prog = new Problem("Character generator");
            var race = new FDVariable <string>("race",
                                               "human", "electroid", "insectoid");
            var cclass = new FDVariable <string>("cclass",
                                                 "fighter", "magic user", "cleric", "thief");

            // Electroids are atheists
            prog.Inconsistent(race == "electroid", cclass == "cleric");

            // Nationalities of humans
            var nationality = new FDVariable <string>("nationality", race == "human",
                                                      "landia", "placeville", "cityburgh");
            // Religions of clerics
            var religion = new FDVariable <string>("religion", cclass == "cleric",
                                                   "monotheist", "pantheist", "lovecraftian", "dawkinsian");

            // Lovecraftianism is outlawed in Landia
            prog.Inconsistent(nationality == "landia", religion == "lovecraftian");
            // Insectoids believe in strict hierarchies
            prog.Inconsistent(race == "insectoid", religion == "pantheist");
            // Lovecraftianism is the state religion of cityburgh
            prog.Inconsistent(nationality == "cityburgh", cclass == "cleric", Not(religion == "lovecraftian"));

            for (int i = 0; i < 100; i++)
            {
                var solution        = prog.Solve();
                var characterObject = new CharacterObject();

                string Value(FDVariable <string> v)
                {
                    return(solution.DefinesVariable(v) ? v.Value(solution) : null);
                }

                solution.Populate(characterObject);
                Assert.AreEqual(Value(race), characterObject.race);
                Assert.AreEqual(Value(cclass), characterObject.cclass);
                Assert.AreEqual(Value(nationality), characterObject.nationality);
                Assert.AreEqual(Value(religion), characterObject.religion);
                Console.WriteLine(solution.Model);
            }
        }