public void Test_Mill_NotEnoughWood()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New(EngineSettings.DefaultVerbose);

            var person = new Person(context.Settings);

            var tile = context.World.Tiles[0];

            tile.AddPerson(person);

            var needEntry = new NeedEntry(ActivityVerb.Mill, ItemType.Timber, PersonVitalType.NotSet, 50, 101);

            var activity = new MillTimberActivity(person, needEntry, context.Settings, context.Console);

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            var foundNeedEntry = person.Needs [0];

            Assert.AreEqual(ItemType.Wood, foundNeedEntry.ItemType);
            Assert.AreEqual(90, foundNeedEntry.Quantity);
            Assert.AreEqual(102, foundNeedEntry.Priority);
        }
Example #2
0
        public void Test_EatFood_FoodAvailable()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            var settings = context.Settings;

            var person = new Person(settings);

            person.Inventory [ItemType.Food]      = 100;
            person.Vitals[PersonVitalType.Hunger] = 80;

            var needEntry = new NeedEntry(ActivityVerb.Eat, ItemType.Food, PersonVitalType.NotSet, settings.DefaultEatAmount, settings.DefaultItemPriorities[ItemType.Food]);

            var activity = new EatFoodActivity(person, needEntry, settings, context.Console);

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(75, person.Vitals[PersonVitalType.Hunger]);
        }
Example #3
0
        public void Test_Act_ContinueFelling()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            var settings = EngineSettings.DefaultVerbose;

            settings.FellingRate = 10;

            var person = new PersonCreator(settings).CreateAdult();

            var tile = context.World.Tiles[0];

            tile.AddPerson(person);
            tile.AddTrees(new PlantCreator(context.Settings).CreateTrees(2));

            var needEntry = new NeedEntry(ActivityVerb.Fell, ItemType.Wood, PersonVitalType.NotSet, 50, 101);

            var activity = new FellWoodActivity(person, needEntry, settings, new ConsoleHelper(settings));

            activity.Target = tile.Trees [0];

            Console.WriteLine("");
            Console.WriteLine("Executing target");
            Console.WriteLine("");

            activity.Act(person);

            Assert.AreEqual(10, activity.Target.PercentHarvested);
        }
        public void Test_Act_WoodIsAvailable()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New(EngineSettings.DefaultVerbose);

            context.Settings.TimberMillingRate = 50;

            var person = new Person(context.Settings);

            person.Inventory.Items[ItemType.Wood] = 100;

            var tile = context.World.Tiles[0];

            tile.AddPerson(person);

            var needEntry = new NeedEntry(ActivityVerb.Mill, ItemType.Timber, PersonVitalType.NotSet, 50, 101);

            var activity = new MillTimberActivity(person, needEntry, context.Settings, context.Console);

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(50, person.Inventory.Items [ItemType.Timber]);
            Assert.AreEqual(10, person.Inventory.Items [ItemType.Wood]);
        }
        public void Test_Sleep_ShelterAvailable()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            context.World.Logic.AddActivity(typeof(DrinkWaterActivity));

            var settings = context.Settings;

            var person = new Person(settings);

            person.Vitals[PersonVitalType.Energy] = 0;

            person.Home = new Building(BuildingType.Shelter, settings);
            person.Home.PercentComplete = 100;

            var needEntry = new NeedEntry(ActivityVerb.Sleep, ItemType.NotSet, PersonVitalType.Energy, 100, settings.DefaultVitalPriorities[PersonVitalType.Energy]);

            var activity = new SleepActivity(person, needEntry, settings, new ConsoleHelper(settings));

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(settings.EnergyFromSleepRate, person.Vitals[PersonVitalType.Energy]);
        }
Example #6
0
        public void Test_GetThirstyCollectWaterAndDrink()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            context.Data.IsVerbose = true;

            context.Settings.DefaultCollectWaterRate = 50; // Increase the rate of water collection so the test goes faster
            context.Settings.DefaultDrinkAmount      = 20; // Increase the amount the person drinks so the test goes faster
            context.Settings.WaterForThirstRatio     = 10;

            // Disabled otherwise the thirst vital will never remain at zero
            //context.World.Logic.AddEffect (new ThirstEffect(context.Settings, context.Console));

            context.World.Logic.AddNeed(new DrinkWaterNeedIdentifier(context.Settings, context.Console));

            context.World.Logic.AddActivity(typeof(CollectWaterActivity));
            context.World.Logic.AddActivity(typeof(DrinkWaterActivity));

            var tile = context.World.Tiles [0];

            tile.Inventory[ItemType.Water] = 200;

            var person = new PersonCreator(context.Settings).CreateAdult();  // TODO: Store the PersonCreator object somewhere else

            person.Vitals[PersonVitalType.Thirst] = 90;

            tile.AddPerson(person);

            context.Player = person;

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            context.Initialize();  // TODO: Should Start be part of the test? Or part of the preparation before the above console output?

            context.Run(10);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(0, person.Vitals[PersonVitalType.Thirst]);
        }
Example #7
0
        public void Test_DecideAndBuildShelter()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            context.Data.IsVerbose = true;

            context.Settings.MinimumTreeSize       = 90;   // Increase the size of the trees to speed up test
            context.Settings.WoodRequiredForTimber = 1.1m; // Reduce the waste rate to increase the speed of the test
            context.Settings.ConstructionRate      = 50;   // Increase construction rate to speed up test
            context.Settings.TimberMillingRate     = 50;
            context.Settings.FellingRate           = 50;

            context.World.Logic.AddNeed(new BuildShelterNeedIdentifier(context.Settings, context.Console));
            //context.World.Logic.AddDecision (new ShelterDecision ());
            context.World.Logic.AddActivity(typeof(BuildShelterActivity));
            context.World.Logic.AddActivity(typeof(MillTimberActivity));
            context.World.Logic.AddActivity(typeof(FellWoodActivity));

            var tile = context.World.Tiles [0];

            var person = new PersonCreator(context.Settings).CreateAdult();  // TODO: Store the PersonCreator object somewhere else

            tile.AddPerson(person);
            tile.AddTrees(new PlantCreator(context.Settings).CreateTrees(10));                // TODO: Should this PlantCreator object be stored somewhere better?

            context.Player = person;

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            context.Initialize();              // TODO: Should Start be part of the test? Or part of the preparation before the above console output?

            context.Run(20);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.IsNotNull(person.Home);
            Assert.AreEqual(100, person.Home.PercentComplete);
            Assert.AreEqual(null, person.Activity);
        }
Example #8
0
        public void Test_Act_FinishedFelling()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            var settings = EngineSettings.DefaultVerbose;

            settings.FellingRate = 10;

            var person = new PersonCreator(settings).CreateAdult();

            var tile = context.World.Tiles[0];

            tile.AddPerson(person);
            tile.AddTrees(new PlantCreator(context.Settings).CreateTrees(2));

            var needEntry = new NeedEntry(ActivityVerb.Fell, ItemType.Wood, PersonVitalType.NotSet, 50, 101);

            person.AddNeed(needEntry);

            var activity = new FellWoodActivity(person, needEntry, settings, new ConsoleHelper(settings));

            activity.Target = tile.Trees [0];
            activity.Target.PercentHarvested = 100;
            activity.TotalWoodFelled         = 40;     // Add just enough so the activity can finish

            var totalWoodExpected = activity.Target.Size;

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Assert.IsTrue(activity.IsFinished);
            Assert.IsNull(activity.Target);
            Assert.AreEqual(totalWoodExpected, person.Inventory.Items [ItemType.Wood]);

            Assert.AreEqual(0, person.Needs.Count);
        }
        public void Test_GetTiredAndSleep()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            context.Settings.DefaultGatherFoodRate = 50;  // Increase the rate of food gathering so the test goes faster
            context.Settings.DefaultEatAmount      = 100; // Increase the amount the person eats so the test goes faster

            context.World.Logic.AddNeed(new SleepNeedIdentifier(context.Settings, context.Console));
            context.World.Logic.AddActivity(typeof(SleepActivity));

            var tile = context.World.Tiles [0];

            var person = context.World.PersonCreator.CreateAdult();

            person.Vitals[PersonVitalType.Energy] = 0;

            tile.AddPerson(person);

            context.Player = person;

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            context.Initialize();  // TODO: Should Start be part of the test? Or part of the preparation before the above console output?

            var numberOfCycles = 5;

            context.Run(numberOfCycles);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            var expectedEnergy = context.Settings.EnergyFromSleepRate * numberOfCycles / 2; // Divide by 2 because the person has no shelter.

            Assert.AreEqual(expectedEnergy, person.Vitals[PersonVitalType.Energy]);
        }
Example #10
0
        public void Test_GetHungryCollectFoodAndEat()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            context.Settings.DefaultGatherFoodRate = 50;  // Increase the rate of food gathering so the test goes faster
            context.Settings.DefaultEatAmount      = 100; // Increase the amount the person eats so the test goes faster

            context.World.Logic.AddNeed(new EatFoodNeedIdentifier(context.Settings, context.Console));
            context.World.Logic.AddActivity(typeof(GatherFoodActivity));
            context.World.Logic.AddActivity(typeof(EatFoodActivity));

            var tile = context.World.Tiles [0];

            tile.Inventory[ItemType.Food] = 200;

            var person = new PersonCreator(context.Settings).CreateAdult();  // TODO: Store the PersonCreator object somewhere else

            person.Vitals[PersonVitalType.Hunger] = 90;

            tile.AddPerson(person);

            context.Player = person;

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            context.Initialize();  // TODO: Should Start be part of the test? Or part of the preparation before the above console output?

            context.Run(5);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(40, person.Vitals[PersonVitalType.Hunger]);
        }
        public void Test_DrinkWater_WaterAvailable()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            context.World.Logic.AddActivity(typeof(DrinkWaterActivity));

            var settings = context.Settings;

            settings.DefaultDrinkAmount = 10; // Increase the drink rate to speed up test

            var person = new Person(settings);

            person.Inventory [ItemType.Water]     = 100;
            person.Vitals[PersonVitalType.Thirst] = 80;

            var needEntry = new NeedEntry(
                ActivityVerb.Drink,
                ItemType.Water,
                PersonVitalType.Thirst,
                settings.DefaultDrinkAmount,
                settings.DefaultItemPriorities[ItemType.Water]
                );

            var activity = new DrinkWaterActivity(person, needEntry, settings, new ConsoleHelper(settings));

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(70, person.Vitals[PersonVitalType.Thirst]);
        }
Example #12
0
        public void Test_GatherFood_FoodAvailable()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New();

            // TODO: Remove if not needed
            //context.World.Logic.AddActivity (typeof(GatherFoodActivity));

            var settings = context.Settings;

            var tile = context.World.Tiles [0];

            tile.Inventory [ItemType.Food] = 100;

            var person = new Person(settings);

            person.Tile = tile;

            var needEntry = new NeedEntry(ActivityVerb.Gather, ItemType.Food, PersonVitalType.Hunger, settings.DefaultEatAmount, settings.DefaultItemPriorities[ItemType.Food]);

            var activity = new GatherFoodActivity(person, needEntry, settings, context.Console);

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(10, person.Inventory.Items[ItemType.Food]);
        }
Example #13
0
        public void Test_CollectWater_WaterAvailable()
        {
            Console.WriteLine("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New(EngineSettings.DefaultVerbose);

            context.World.Logic.AddActivity(typeof(CollectWaterActivity));

            var settings = context.Settings;

            var tile = context.World.Tiles [0];

            tile.Inventory [ItemType.Water] = 100;

            var person = new Person(settings);

            person.Tile = tile;

            var needEntry = new NeedEntry(ActivityVerb.Gather, ItemType.Water, PersonVitalType.Thirst, settings.DefaultDrinkAmount, settings.DefaultItemPriorities[ItemType.Water]);

            var activity = new CollectWaterActivity(person, needEntry, settings, new ConsoleHelper(settings));

            Console.WriteLine("");
            Console.WriteLine("Executing test");
            Console.WriteLine("");

            activity.Act(person);

            Console.WriteLine("");
            Console.WriteLine("Analysing test");
            Console.WriteLine("");

            Assert.AreEqual(10, person.Inventory.Items[ItemType.Water]);
        }