public void SolveSecondPuzzle()
        {
            var sut = new AgeModel(REAL_AGES);

            sut.Advance(256);
            Assert.Equal(1702631502303, sut.CountAllFishes());
        }
        public void SolveFirstPuzzle()
        {
            var sut = new AgeModel(REAL_AGES);

            sut.Advance(80);
            Assert.Equal(379114, sut.CountAllFishes());
        }
        public void CalculateSpawnRateCorrectly_WhenSampleDataIsUsed(int days, long expectedFishes)
        {
            var sut = new AgeModel(SAMPLE_AGES);

            sut.Advance(days);
            Assert.Equal(expectedFishes, sut.CountAllFishes());
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            AgeModel ageModel = await db.AgeModel.FindAsync(id);

            db.AgeModel.Remove(ageModel);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "AgeId,Age")] AgeModel ageModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ageModel).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(ageModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "AgeId,Age")] AgeModel ageModel)
        {
            if (ModelState.IsValid)
            {
                db.AgeModel.Add(ageModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(ageModel));
        }
        public void ReturnAllAges_WhenInitializedWithMoreThanOneValue()
        {
            var sut = new AgeModel(SAMPLE_AGES);

            Assert.Equal(0, sut.CountFishesWithAnAgeOf(0));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(1));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(2));
            Assert.Equal(2, sut.CountFishesWithAnAgeOf(3));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(4));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(5));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(6));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(7));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(8));
        }
        public void ReturnOneAge_WhenInitializedWithAsingleValue()
        {
            var sut = new AgeModel("3");

            Assert.Equal(0, sut.CountFishesWithAnAgeOf(0));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(1));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(2));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(3));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(4));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(5));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(6));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(7));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(8));
        }
        // GET: AgeModels/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AgeModel ageModel = await db.AgeModel.FindAsync(id);

            if (ageModel == null)
            {
                return(HttpNotFound());
            }
            return(View(ageModel));
        }
        public void DecrementInternalTimerCorrectly_WhenThereAreSeveralFishes()
        {
            var sut = new AgeModel(SAMPLE_AGES);

            sut.Advance(1);
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(0));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(1));
            Assert.Equal(2, sut.CountFishesWithAnAgeOf(2));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(3));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(4));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(5));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(6));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(7));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(8));
        }
        public void SpawnNewLanternfish_WhenFourDaysPassAfterInitialAgeOf3()
        {
            var sut = new AgeModel("3");

            sut.Advance(4);
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(0));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(1));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(2));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(3));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(4));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(5));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(6));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(7));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(8));
        }
        public void DecrementInternalTimerCorrectly_WhenThereIsOneFish()
        {
            var sut = new AgeModel("3");

            sut.Advance(1);
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(0));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(1));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(2));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(3));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(4));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(5));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(6));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(7));
            Assert.Equal(0, sut.CountFishesWithAnAgeOf(8));
        }
        public void SpawnFishCorrectly_When18DaysPass()
        {
            var sut = new AgeModel(SAMPLE_AGES);

            sut.Advance(18);
            Assert.Equal(3, sut.CountFishesWithAnAgeOf(0));
            Assert.Equal(5, sut.CountFishesWithAnAgeOf(1));
            Assert.Equal(3, sut.CountFishesWithAnAgeOf(2));
            Assert.Equal(2, sut.CountFishesWithAnAgeOf(3));
            Assert.Equal(2, sut.CountFishesWithAnAgeOf(4));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(5));
            Assert.Equal(5, sut.CountFishesWithAnAgeOf(6));
            Assert.Equal(1, sut.CountFishesWithAnAgeOf(7));
            Assert.Equal(4, sut.CountFishesWithAnAgeOf(8));
        }
        public void PassAgeAtEndOfYear()
        {
            // Tests a birthdate of 12/31/2021 with method AgeByEndOfYear()
            // Arrange
            AgeModel age = new AgeModel();

            age.BirthDate = new DateTime(2021, 12, 31, 12, 0, 0);
            int expected = 0;

            // Act
            int actual = age.AgeByEndOfYear();

            // Assert
            Assert.Equal(actual, expected);
        }
        public void PassAgeThisYear()
        {
            // Tests a birthdate of 3/1/2000 with method AgeThisYear()
            // Arrange
            AgeModel age = new AgeModel();

            age.BirthDate = new DateTime(2000, 3, 1, 7, 0, 0);
            int expected = 20;

            // Act
            int actual = age.AgeThisYear();

            // Assert
            Assert.Equal(actual, expected);
        }
        public void PassAgeThisYearFive()
        {
            // Tests a birthdate of 2/9/2020 with method AgeThisYear()
            // Arrange
            AgeModel age = new AgeModel();

            age.BirthDate = new DateTime(2020, 2, 9, 12, 0, 0);
            int expected = 1;

            // Act
            int actual = age.AgeThisYear();

            // Assert
            Assert.Equal(actual, expected);
        }
        public void PassAgeThisYearThree()
        {
            // Tests a birthdate of 6/9/1990 with method AgeThisYear()
            // Arrange
            AgeModel age = new AgeModel();

            age.BirthDate = new DateTime(1990, 6, 9, 23, 0, 0);
            int expected = 30;

            // Act
            int actual = age.AgeThisYear();

            // Assert
            Assert.Equal(actual, expected);
        }
 public IActionResult Index(AgeModel model)
 {
     if (ModelState.IsValid)                              // Check valid state
     {
         ViewBag.Age            = model.AgeThisYear();    // Call AgeThisYear() function and assign
         ViewBag.AgeAtEndOfYear = model.AgeByEndOfYear(); // Call AgeByEndOfYear() function and assign
         ViewBag.Name           = model.Name;             // Assign name
     }
     else // Assign defaults
     {
         ViewBag.Age            = 0;
         ViewBag.AgeAtEndOfYear = 0;
         ViewBag.Name           = "";
     }
     return(View(model));
 }
Exemple #19
0
        public static AgeModel GetAge(int dob_year, int dob_month, int dob_day, DateTime today)
        {
            if (dob_year > 0 && dob_month > 0 && dob_day > 0)
            {
                DateTime dob = new DateTime(dob_year, dob_month, dob_day);

                int months = today.Month - dob.Month;
                int years  = today.Year - dob.Year;

                if (today.Day < dob.Day)
                {
                    months--;
                }

                if (months < 0)
                {
                    years--;
                    months += 12;
                }

                int days = (today - dob.AddMonths((years * 12) + months)).Days;

                AgeModel mAgeModel = new AgeModel();
                mAgeModel.Year       = years;
                mAgeModel.Month      = months;
                mAgeModel.Day        = days;
                mAgeModel.TotalYear  = mAgeModel.Year;
                mAgeModel.TotalMonth = mAgeModel.Year * 12 + mAgeModel.Month;
                mAgeModel.TotalDay   = (int)(today - dob).TotalDays;
                mAgeModel.TotalWeek  = mAgeModel.TotalDay / 7;
                mAgeModel.TotalHour  = mAgeModel.TotalDay * 24;
                return(mAgeModel);
            }
            else
            {
                AgeModel mAgeModel = new AgeModel();
                mAgeModel.Year       = today.Year - dob_year;
                mAgeModel.Month      = 0;
                mAgeModel.Day        = 0;
                mAgeModel.TotalYear  = mAgeModel.Year;
                mAgeModel.TotalMonth = mAgeModel.Year * 12;
                mAgeModel.TotalWeek  = mAgeModel.Year * 52;
                mAgeModel.TotalDay   = mAgeModel.Year * 365;
                mAgeModel.TotalHour  = mAgeModel.Year * 365 * 24;
                return(mAgeModel);
            }
        }
Exemple #20
0
        private readonly PersonModelValidator validator; //zm



        public PersonViewModel()                      //konstr
        {
            personModel = new PersonModel();          //instancja modelu
            validator   = new PersonModelValidator(); //instancja modelu
            Age         = new AgeModel();             //instancja modelu

            //poniżej VM wykonuje komendy MenuItem, gdzie jest wołane GetMenuItem, wchodzimy nazwą(string) i akcją
            //własności klasy MenuItem Hearder i Command są odpowiednio przypisane
            Menu.Add(GetMenuItem("1. Change the name", InputName));
            Menu.Add(GetMenuItem("2. Change the foreground color to red", () => SetForegroundColor(ConsoleColor.DarkRed)));
            Menu.Add(GetMenuItem("3. Change the foreground color to green", () => SetForegroundColor(ConsoleColor.DarkGreen)));
            Menu.Add(GetMenuItem("4. Change the foreground color to white", () => SetForegroundColor(ConsoleColor.White)));
            Menu.Add(GetMenuItem("5. Change the background color to cyan", () => SetBackgroundColor(ConsoleColor.DarkCyan)));
            Menu.Add(GetMenuItem("6. Change the background color to yellow", () => SetBackgroundColor(ConsoleColor.DarkYellow)));
            Menu.Add(GetMenuItem("7. Change the background color to black", () => SetBackgroundColor(ConsoleColor.Black)));
            Menu.Add(GetMenuItem("q. Quit", () => Environment.Exit(0)));
        }
Exemple #21
0
        public static void Postfix(ref Hero __result)
        {
            //var faction = __result.MapFaction;
            // It appears that gang leaders, merchants, and preachers have some female representation. Will skip them in that case.
            if ((__result.IsArtisan || __result.IsRuralNotable || __result.IsHeadman) && !__result.IsFemale)
            {
                __result.UpdatePlayerGender(MBRandom.RandomFloat < D225MiscFixesSettingsUtil.Instance.WorkerGenderRatio);
                NameGenerator.Current.GenerateHeroNameAndHeroFullName(__result, out var firstName, out var fullName, false);
                __result.SetName(fullName, firstName);
            }

            AgeModel ageModel = Campaign.Current.Models.AgeModel;
            int      baseAge  = Math.Max(ageModel.HeroComesOfAge, LocationCharacterConstructorPatch.TweenAge);

            if (__result.IsNotable)
            {
                __result.SetBirthDay(HeroHelper.GetRandomBirthDayForAge(
                                         MathF.Lerp(baseAge, ageModel.MaxAge, (__result.Age - ageModel.HeroComesOfAge) / (ageModel.MaxAge - ageModel.HeroComesOfAge))));
            }
        }
Exemple #22
0
 public AgeSetupView()
 {
     this.model       = new AgeModel();
     this.DataContext = model;
     this.InitializeComponent();
 }
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new AgeModel();
 }
        private static void CopyAgeImages(AgeModel model, string filePath, string output)
        {
            switch (model.Age)
            {
            case int age when(age > 0 && age <= 5):
                File.Copy(filePath, Path.Combine(output, "5", model.Filename));

                break;

            case int age when(age > 5 && age <= 10):
                File.Copy(filePath, Path.Combine(output, "10", model.Filename));

                break;

            case int age when(age > 10 && age <= 15):
                File.Copy(filePath, Path.Combine(output, "15", model.Filename));

                break;

            case int age when(age > 15 && age <= 20):
                File.Copy(filePath, Path.Combine(output, "20", model.Filename));

                break;

            case int age when(age > 20 && age <= 25):
                File.Copy(filePath, Path.Combine(output, "25", model.Filename));

                break;

            case int age when(age > 25 && age <= 30):
                File.Copy(filePath, Path.Combine(output, "30", model.Filename));

                break;

            case int age when(age > 30 && age <= 35):
                File.Copy(filePath, Path.Combine(output, "35", model.Filename));

                break;

            case int age when(age > 35 && age <= 40):
                File.Copy(filePath, Path.Combine(output, "40", model.Filename));

                break;

            case int age when(age > 40 && age <= 45):
                File.Copy(filePath, Path.Combine(output, "45", model.Filename));

                break;

            case int age when(age > 45 && age <= 50):
                File.Copy(filePath, Path.Combine(output, "50", model.Filename));

                break;

            case int age when(age > 50 && age <= 55):
                File.Copy(filePath, Path.Combine(output, "55", model.Filename));

                break;

            case int age when(age > 55 && age <= 60):
                File.Copy(filePath, Path.Combine(output, "60", model.Filename));

                break;

            case int age when(age > 60 && age <= 120):
                File.Copy(filePath, Path.Combine(output, "65", model.Filename));

                break;

            default:
                break;
            }
        }
Exemple #25
0
        public static void Prefix(AgentData agentData)
        {
            try
            {
                AgeModel ageModel = Campaign.Current?.Models?.AgeModel;
                if (ageModel == default)
                {
                    return;
                }

                BasicCharacterObject character = agentData.AgentCharacter;
                if (character is CharacterObject)
                {
                    CultureObject culture = (character as CharacterObject).Culture;
                    if (culture == default)
                    {
                        return;
                    }

                    int randMin = agentData.AgentAge;
                    int randMax = randMin;

                    // Rather spaghetti-ish, but should do better performance wise
                    if (character == culture.Barber || character == culture.ShopWorker || character == culture.TavernGamehost || character == culture.Tavernkeeper ||
                        character == culture.Musician || character == culture.Armorer || character == culture.Blacksmith || character == culture.HorseMerchant ||
                        character == culture.Merchant || character == culture.Weaponsmith || character == culture.GangleaderBodyguard)
                    {
                        randMin = TeenAge;
                        randMax = ageModel.BecomeOldAge;
                        agentData.IsFemale(MBRandom.RandomFloat < D225MiscFixesSettingsUtil.Instance.WorkerGenderRatio);
                    }
                    else if (character == culture.ArtisanNotary || character == culture.MerchantNotary || character == culture.PreacherNotary ||
                             character == culture.RuralNotableNotary || character == culture.RansomBroker)
                    {
                        randMin = AdultAge;
                        randMax = ageModel.MaxAge;
                        agentData.IsFemale(MBRandom.RandomFloat < D225MiscFixesSettingsUtil.Instance.WorkerGenderRatio);
                    }
                    else if (character == culture.MeleeMilitiaTroop || character == culture.RangedMilitiaTroop ||
                             character == culture.MilitiaSpearman || character == culture.MilitiaArcher)
                    {
                        randMin = TeenAge;
                        randMax = ageModel.BecomeOldAge;
                        agentData.IsFemale(MBRandom.RandomFloat < D225MiscFixesSettingsUtil.Instance.WorkerGenderRatio);
                    }
                    else if (character == culture.MeleeEliteMilitiaTroop || character == culture.RangedEliteMilitiaTroop ||
                             character == culture.MilitiaVeteranSpearman || character == culture.MilitiaVeteranArcher)
                    {
                        randMin = AdultAge;
                        randMax = ageModel.BecomeOldAge;
                        agentData.IsFemale(MBRandom.RandomFloat < D225MiscFixesSettingsUtil.Instance.WorkerGenderRatio);
                    }
                    else if (character == culture.TavernWench || character == culture.FemaleDancer)
                    {
                        randMin = TweenAge;
                        randMax = ageModel.BecomeOldAge;
                    }
                    else if (character == culture.Townsman || character == culture.Townswoman || character == culture.Villager || character == culture.VillageWoman)
                    {
                        randMin = TweenAge;
                        randMax = ageModel.MaxAge;
                    }
                    else if (character == culture.Beggar || character == culture.FemaleBeggar)
                    {
                        randMin = ChildAge;
                        randMax = ageModel.MaxAge;
                    }
                    else if (character == culture.TownsmanInfant || character == culture.TownswomanInfant)
                    {
                        randMin = InfantAge;
                        randMax = ChildAge;
                    }
                    else if (character == culture.TownsmanChild || character == culture.TownswomanChild ||
                             character == culture.VillagerMaleChild || character == culture.VillagerFemaleChild)
                    {
                        randMin = ChildAge;
                        randMax = TeenAge;
                    }
                    else if (character == culture.TownsmanTeenager || character == culture.TownswomanTeenager ||
                             character == culture.VillagerMaleTeenager || character == culture.VillagerFemaleTeenager)
                    {
                        randMin = TeenAge;
                        randMax = AdultAge;
                    }

                    if (agentData.AgeOverriden || randMin != agentData.AgentAge || randMin != randMax)
                    {
                        agentData.Age(MBRandom.RandomInt(randMin, randMax));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Print($"[FixedBanditSpawning] Error attempting to modify location character agent data.\n{e}");
            }
        }