Esempio n. 1
0
        // Method to read menu option
        public static void ReadMenu()
        {
            //Init variables
            int option = 0;

            // Read option
            while (option == 0)
            {
                Console.WriteLine("Please enter an option: ");
                option = Scripts.ReadInt();
                if (option == Scripts.intError)
                {
                    break;
                }
            }

            //Checks through options to execute valid options and reset invalid options
            switch (option)
            {
            case 1:
                // Checks if country is already at the alert level set
                if (Simulation.alertLevel == 1)
                {
                    Console.WriteLine("The country is already at Alert Level {0}! [Please wait...]", Simulation.alertLevel);
                    Thread.Sleep(2000);
                    Draw();
                }
                else
                {
                    Simulation.alertLevel         = 1;
                    Simulation.expenses          -= Simulation.alertLevelExpenses; // Remove previous alertLevelExpenses from expenses
                    Simulation.alertLevelExpenses = 0;                             // Costs nothing to be in Level 1
                    Simulation.expenses          += Simulation.alertLevelExpenses; // Add alertLevelExpenses to total expenses
                    Draw();
                }
                break;

            case 2:
                if (Simulation.alertLevel == 2)
                {
                    Console.WriteLine("The country is already at Alert Level {0}! [Please wait...]", Simulation.alertLevel);
                    Thread.Sleep(2000);
                    Draw();
                }
                else
                {
                    Simulation.alertLevel         = 2;
                    Simulation.expenses          -= Simulation.alertLevelExpenses; // Remove previous alertLevelExpenses from expenses
                    Simulation.alertLevelExpenses = 5000000;                       // Costs $5 million per day to be in Level 2
                    Simulation.expenses          += Simulation.alertLevelExpenses; // Add alertLevelExpenses to total expenses
                    Draw();
                }
                break;

            case 3:
                if (Simulation.alertLevel == 3)
                {
                    Console.WriteLine("The country is already at Alert Level {0}! [Please wait...]", Simulation.alertLevel);
                    Thread.Sleep(2000);
                    Draw();
                }
                else
                {
                    Simulation.alertLevel         = 3;
                    Simulation.expenses          -= Simulation.alertLevelExpenses; // Remove previous alertLevelExpenses from expenses
                    Simulation.alertLevelExpenses = 15000000;                      // Costs $15 million per day to be in Level 3
                    Simulation.expenses          += Simulation.alertLevelExpenses; // Add alertLevelExpenses to total expenses
                    Draw();
                }
                break;

            case 4:
                if (Simulation.alertLevel == 4)
                {
                    Console.WriteLine("The country is already at Alert Level {0}! [Please wait...]", Simulation.alertLevel);
                    Thread.Sleep(2000);
                    Draw();
                }
                else
                {
                    Simulation.alertLevel         = 4;
                    Simulation.expenses          -= Simulation.alertLevelExpenses; // Remove previous alertLevelExpenses from expenses
                    Simulation.alertLevelExpenses = 25000000;                      // Costs $25 million per day to be in Level 4
                    Simulation.expenses          += Simulation.alertLevelExpenses; // Add alertLevelExpenses to total expenses
                    Draw();
                }
                break;

            case 5:
                Simulation.Start(false);     // Re-run loop within simulation without running algorithm
                break;

            default:
                Console.WriteLine("Error: Please enter a valid option [Please Wait...]");
                Thread.Sleep(2000);
                Draw();
                break;
            }
        }
Esempio n. 2
0
        //Method to read menu option
        public static void ReadMenu()
        {
            //Init variables
            int    option = 0;
            string yn     = "";

            //Read option
            Console.Write("Please enter an option: ");
            try
            {
                option = Int32.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("Error: Please enter a postive whole integer [Please wait...]");
                Thread.Sleep(2000);
                Draw(true);
            }

            //Checks through options to execute valid options and reset invalid options
            switch (option)
            {
            // Change Virus Name
            case 1:
                Simulation.virusName = StringReadHandler();     // virusName = The value returned by the string read handler
                Draw(true);
                break;

            // Change R-Value
            case 2:
                Simulation.rValue = DoubleReadHandler(2);     // fatalityRate = The value returned by the double read handler rounded to 2 decimal places
                Draw(true);
                break;

            // Change Fatality Rate
            case 3:
                Simulation.fatalityRate = DoubleReadHandler(2);     // fatalityRate = The value returned by the double read handler rounded to 2 decimal places
                Draw(true);
                break;

            // Change Budget
            case 4:
                Simulation.budget = DoubleReadHandler(0);     // budget = The value returned by the double read handler rounded to 0 decimal places
                Draw(true);
                break;

            // Change Vaccine Cost/Dose
            case 5:
                Simulation.vaccineCost = IntReadHandler();     // vaccineCost = The value returned by the integer read handler
                Draw(true);
                break;

            // Asks if you want to reset, then it resets
            case 6:
                // Ask for Y or N input
                while (yn == "")
                {
                    Console.WriteLine("Are you sure you wish to proceed? [Y/N]");
                    yn = Scripts.ReadString();
                    if (yn == "y" || yn == "Y")     // if yes reset
                    {
                        Simulation.ResetDefaults();
                        Draw(true);
                        break;
                    }
                    else if (yn == "n" || yn == "N")     // if no do not reset
                    {
                        Draw(true);
                        break;
                    }
                    else if (yn != "y" || yn != "n" || yn != "Y" || yn != "N")     // if Y then reset to default settings
                    {
                        Draw(false);
                        yn = "";
                        Console.WriteLine("Error: Please enter Y or N");
                        continue;
                    }
                    Draw(true);
                    break;
                }
                yn = "";
                break;

            case 7:
                MainMenu.Draw();
                break;

            default:
                Console.WriteLine("Error: Please enter a valid option [Please Wait...]");
                Thread.Sleep(2000);
                Draw(true);
                break;
            }
        }
Esempio n. 3
0
        // Virus simulator algorithm
        public static void Simulate()
        {
            newCommunityCases = 0; // Reset new cases at the end of the simulated day

            // Enforce isolation to the fullest at level 4
            if (alertLevel == 4)
            {
                isolationEnforced = true; // No transmission possible (unless the rare possibility of a passenger randomly brings the virus in takes hold)
                workingRValue     = 0;    // Virus transmissibility is 0
            }
            else if (alertLevel == 3)
            {
                isolationEnforced = false; // Transmission is possible
                workingRValue     = 0.1;   // Reduces transmission to a significantly low point
            }
            else if (alertLevel == 2)
            {
                isolationEnforced = false;      // Transmission is possible
                workingRValue     = rValue / 2; // Halves the transmissibility of the virus
            }
            else
            {
                isolationEnforced = false;  // Transmission is possible
                workingRValue     = rValue; // Virus is as transmissible as possible
            }

            // Code to run if vaccinating
            if (vaccinating)
            {
                vaccinations += vaccinationRate; // Add vaccination rate to total vaccinations
            }

            // Array Stepper (Move delayed case counts/Move active case 'timer' array down a step)
            //---------------------------------------------------------------------------------------------------------

            // Move active cases down a step in the array
            for (int i = 1; i <= 13; i++) // Starts at 1 because there are no days before 0 so no point removing
            {
                // Init variable
                double movingValue = 0;

                // Set next day in array to moving variable (current day)
                movingValue       = casesOnDay[i];
                casesOnDay[i - 1] = movingValue;
            }

            // Move new cases down a step in the array
            for (int i = 1; i <= 13; i++) // Starts at 1 because there are no days before 0 so no point removing
            {
                // Init variable
                double movingValue = 0;

                // Set next day in array to moving variable (current day)
                movingValue = newCaseDelayArray[i];
                newCaseDelayArray[i - 1] = movingValue;
            }

            //---------------------------------------------------------------------------------------------------------


            // Get daily imported cases with random number generator
            newImportedCases = Scripts.RandomNumber(maxImported);


            // Spread Calculator (How many newCommunityCases)
            //---------------------------------------------------------------------------------------------------------

            // Runs conditional statements to find new cases depending on border and/or isolation conditions

            /* For Each Ranges OR Iterating using a for
             * https://stackoverflow.com/questions/38379400/c-sharp-int-type-in-foreach-statement */
            if (bordersClosed)                                    // Runs when borders are closed
            {
                if (communityCases > 0)                           // Runs when community cases are greater than 0 while borders are closed
                {
                    if (isolationEnforced == false)               // Runs when borders are closed but isolation is not enforced
                    {
                        for (int i = 1; i <= communityCases; i++) // Variable 'i' can be 1 because community cases are greater than 0
                        {
                            // For each community case, add cases to the delay (2 weeks until test shows positive)
                            newCaseDelayArray[13] += workingRValue;
                        }
                    }
                    else // No transmission when isolation enforced (Level 4)
                    {
                        newCaseDelayArray[13] = 0;
                    }
                }

                // 1 in 100 chance of having a community case outbreak with closed borders
                if (Scripts.RandomNumber(100) == 1)
                {
                    newCommunityCases++;
                }
            }
            else // Runs when borders are opened
            {
                if (isolationEnforced == false) // Runs when borders are open and isolation is not enforced ( < Level 4)
                {
                    for (int i = 1; i <= communityCases; i++) // Variable 'i' can be 1 because community cases are greater than 0
                    {
                        // For each community case, add cases to the delay (2 weeks until test shows positive)
                        newCaseDelayArray[13] += workingRValue;
                    }
                }
                else // No transmission when isolation enforced (Level 4)
                {
                    newCaseDelayArray[13] = 0;
                }

                newCommunityCases += newImportedCases; // Imported cases count as community cases with open borders
            }

            //---------------------------------------------------------------------------------------------------------

            // Increase maxImported cases possibility if borders are open
            maxImported++;

            // Add new community cases from delay array
            newCommunityCases += newCaseDelayArray[0];

            // Round case values down (Must happen after newCommunityCases and newImportedCases are calculated for rValue to work)
            // **Code from Microsoft Docs Math.Round (https://docs.microsoft.com/en-us/dotnet/api/system.math.round?view=net-5.0)**
            newImportedCases  = Math.Round(newImportedCases, 0, MidpointRounding.ToNegativeInfinity);  // Rounds number down to a whole person
            newCommunityCases = Math.Round(newCommunityCases, 0, MidpointRounding.ToNegativeInfinity); // Rounds number down to a whole person


            //---------------------------------------------------------------------------------------------------------

            /* Add new community cases, total cases, set casesOnDay[13] variable to today's cases, active cases,
             * closed cases, deaths, recoveries, population decrease and calculate budget changes */

            // Conditional statement that changes totalCases equation based on border status
            // (Because imported cases count as community cases when the borders are open, a different calculation is required for closed borders)
            if (bordersClosed)
            {
                totalCases  += newImportedCases + newCommunityCases; // Sum for total cases
                activeCases += newImportedCases + newCommunityCases; // New cases for today get added onto activeCases
            }
            else
            {
                activeCases += newCommunityCases;
                totalCases  += newCommunityCases;
            }

            communityCases += newCommunityCases;                    // Add new community cases to community case count
            casesOnDay[13]  = newCommunityCases + newImportedCases; // Add new community cases and imported cases to new cases on this day
            activeCases    -= casesOnDay[0];                        // Remove cases from active cases if it has been 14 days
            importedCases  += newImportedCases;                     // Adds newImportedCases to the total importedCases count
            closedCases    += casesOnDay[0];                        // Adds all cases that have finished their 14 days to closedCases variable
            newDeaths       = casesOnDay[0] * fatalityRate / 100;   // New deaths equal cases after 14 days multiplied by the fatality rate divided by 100 to get a calculatable percentage
            newDeaths       = Math.Round(newDeaths, 0, MidpointRounding.ToNegativeInfinity);
            deaths         += newDeaths;                            // Add new deaths to total deaths
            population     -= newDeaths;                            // Remove newDeaths from population
            recoveredCases += casesOnDay[0] - newDeaths;            // Recovered cases equal cases after 14 days minus the death toll of the day
            budget         -= expenses;

            //---------------------------------------------------------------------------------------------------------

            // Check if game is over
            if (activeCases >= population)
            {
                gameRunning   = false;               // Stop simulation loop
                finishSuccess = "herd_infection";    // Player did not succeed (everyone infected)
            }
            else if (vaccinations >= population * 2) // *2 because 2 dose vaccine
            {
                gameRunning   = false;               // Stop simulation loop
                finishSuccess = "vaccinated";        // Player succeeded
            }
            else if (budget <= 0)
            {
                gameRunning   = false;   // Stop simulation loop
                finishSuccess = "money"; // Player failed (ran out of money)
            }
            else
            {
                day++; // Increment day if sim not finished
            }
        }
Esempio n. 4
0
        // Method to read menu option
        public static void ReadMenu()
        {
            //Init variables
            int option = 0;

            // Read option
            while (option == 0)
            {
                Console.WriteLine("Please enter an option: ");
                option = Scripts.ReadInt();
                if (option == Scripts.intError)
                {
                    break;
                }
            }

            // Checks through options to execute valid options and reset invalid options
            switch (option)
            {
            case 1:
                // Only run if vaccinations have not started yet
                if (Simulation.vaccinating)
                {
                    Console.WriteLine("You are already vaccinating! [Please wait...]");
                    Thread.Sleep(2000);
                    Draw();
                }
                else
                {
                    Simulation.budget          -= (Simulation.vaccineCost * 2) * Simulation.population; // Subtract total vaccine price from budget
                    Simulation.expenses        -= Simulation.vaccineExpenses;                           // Remove previous vaccine expenses before adding new ones
                    Simulation.vaccineExpenses += 2000000;                                              // 2 million per 25k vaccinations
                    Simulation.vaccinationRate += 25000;                                                // 25k people vaccinated per day initially
                    Simulation.expenses        += Simulation.vaccineExpenses;                           // Add updated vaccineExpenses to expenses
                    Simulation.vaccinating      = true;                                                 // Start vaccinating population
                    Draw();
                }
                break;

            case 2:
                // Don't run if vaccinationRate exceeds the population
                if (Simulation.vaccinationRate > Simulation.population - 25000)
                {
                    Console.WriteLine("That rate exceeds the population! [Please wait...]");
                    Thread.Sleep(2000);
                    Draw();
                }
                else
                {
                    Simulation.expenses        -= Simulation.vaccineExpenses; // Remove previous vaccine expenses before adding new ones
                    Simulation.vaccineExpenses += 2000000;                    // 2 million per 25k vaccinations
                    Simulation.vaccinationRate += 25000;                      // 25k people vaccinated per day initially
                    Simulation.expenses        += Simulation.vaccineExpenses; // Add updated vaccineExpenses to expenses
                    Draw();
                }
                break;

            case 3:
                Simulation.Start(false);     // Re-run loop within simulation without running algorithm
                break;

            default:
                Console.WriteLine("Error: Please enter a valid option [Please Wait...]");
                Thread.Sleep(2000);
                Draw();
                break;
            }
        }
Esempio n. 5
0
        public static void govOptions()
        {
            Console.WriteLine();
            Console.WriteLine(" --------------------------");
            Console.WriteLine("| Government Interventions |");
            Console.WriteLine("| 1: Border Condition      |");
            Console.WriteLine("| 2: Alert Level           |");
            Console.WriteLine("| 3: Vaccines              |");
            Console.WriteLine("| 4: Continue              |");
            Console.WriteLine("| 5: Cancel Simulation     |");
            Console.WriteLine(" --------------------------");

            /*
             * Options
             */

            // Variables
            int option = 0;

            // Read option
            while (option == 0)
            {
                Console.WriteLine("Please enter an option: ");
                option = Scripts.ReadInt();
                if (option == Scripts.intError)
                {
                    break;
                }
            }

            // Act on the entered option
            switch (option)
            {
            case 1:
                BorderState.Start();     // Run border state mini application
                break;

            case 2:
                AlertLevel.Start();     // Run alert level mini application
                break;

            case 3:
                if (day < 80)
                {
                    Console.WriteLine("You cannot vaccinate until day 80! [Please Wait...]");
                    Thread.Sleep(2000);
                    Draw(false);     // Re-draw information without simulating
                }
                else
                {
                    Vaccinations.Start();     // Run vaccinations mini application
                }
                break;

            case 4:
                break;

            case 5:
                gameRunning = false;
                break;

            default:
                Console.WriteLine("Error: Please enter a valid option [Please Wait...]");
                Thread.Sleep(2000);
                Draw(false);     // Re-draw information without simulating
                break;
            }
        }