示例#1
0
    //END OF UPDTADE()

    //write an external log of the statistics of the gameplay of the user
    public void writeToLog(string countryName, string guessTime, string hint1, string hint2)
    {
        IOOperations.WriteToSave("Country: " + countryName + "\n", true, false);
        IOOperations.WriteToSave("Correct Guess Time: " + guessTime + "\n");
        IOOperations.WriteToSave("Hint Level 1: " + hint1 + "\n");
        IOOperations.WriteToSave("Hint Level 2: " + hint2, false, true);
    }
示例#2
0
        async public void test2()
        {
            // calling function to aggregate
            await AggregatePopGDPAsync.AggregateGdpPopAsync(@"../../../../AggregateGDPPopulation/data/datafile.csv");

            // creating actual and expected strings to compare
            string expecteddata = await IOOperations.ReadfileAsync(@"../../../expected-output.json");;
            string actualdata   = await IOOperations.ReadfileAsync(@"../../../../AggregateGDPPopulation/data/output.json");

            Assert.Equal(expecteddata, actualdata);
        }
示例#3
0
        static void Main(string[] args)
        {
            List <int> numbers = new List <int>
            {
                4, 2, 2, 5, 2, 3, 2, 3, 1, 5, 2
            };

            List <int> subSequence = FindLongestSubsequence(numbers);

            IOOperations.PrintNumbers(subSequence);
        }
示例#4
0
        static void Main(string[] args)
        {
            List <int> numbers = new List <int>
            {
                4, 2, 2, 5, 2, 3, 2, 3, 1, 5, 2
            };

            List <int> even = RemoveOddInList(numbers);

            IOOperations.PrintNumbers(even);
        }
        static void Main(string[] args)
        {
            List <int> numbers = new List <int>
            {
                1, -2, 3, -4, 5, -6, 7, -8
            };

            List <int> positiveNumbers = (from number in numbers
                                          where number > 0
                                          select number).ToList();

            IOOperations.PrintNumbers(positiveNumbers);
        }
        public async Task Test1Async()
        {
            AggregateGDPPopulation AGP = new AggregateGDPPopulation();
            await AGP.performAggregateOperation();

            Task <string> actualstring   = IOOperations.ReadFileToEndAsync("../../../../AggregateGDPPopulation/output/output.json");
            Task <string> expectedstring = IOOperations.ReadFileToEndAsync("../../../expected-output.json");
            string        actual         = await actualstring;
            string        expected       = await expectedstring;
            JObject       ExpectedJO     = JSONOperations.JSONDeserialize(actual);
            JObject       ActualJO       = JSONOperations.JSONDeserialize(expected);

            Assert.Equal(ExpectedJO, ActualJO);
        }
        static void Main(string[] args)
        {
            List <int> numbers = new List <int>();

            IOOperations.GetNumbers(numbers);

            // another way
            // numbers.Sort();

            numbers = (from number in numbers
                       orderby number ascending
                       select number).ToList();

            IOOperations.PrintNumbers(numbers);
        }
示例#8
0
        private async void SaveOptimizationResult()
        {
            var dlg = new SaveFileDialog
            {
                DefaultExt = "json",
                Filter     = "Json (*.json)|*.json"
            };

            if (dlg.ShowDialog() == true)
            {
                await IOOperations.SaveAsync <OptimizationResult>(dlg.FileName, OptimizationResult);

                SetStatusMessage("Result saved.");
            }
        }
示例#9
0
        private async void SaveDataset()
        {
            var dlg = new SaveFileDialog
            {
                DefaultExt = "json",
                Filter     = "Json (*.json)|*.json"
            };

            if (dlg.ShowDialog() == true)
            {
                await IOOperations.SaveAsync <TestcaseBlockerDataset>(dlg.FileName, Dataset);

                SetStatusMessage("Dataset saved.");
            }
        }
示例#10
0
        public static async Task SaveDataset(TestcaseBlockerDataset dataset)
        {
            if (dataset is null)
            {
                Console.WriteLine("Cannot save an empty dataset. First generate or load a dataset.");
                return;
            }

            Console.Write("Enter filename without extension: ");
            string filename = Console.ReadLine();

            var path = Path.Combine(GetDataPath(), filename + ".json");

            Console.WriteLine($"Saving dataset to {path}");

            await IOOperations.SaveAsync <TestcaseBlockerDataset>(path, dataset);
        }
示例#11
0
        public static async Task <TestcaseBlockerDataset> LoadDataset()
        {
            Console.Write("Enter filename without extension: ");
            string filename = Console.ReadLine();

            var path = Path.Combine(GetDataPath(), filename + ".json");

            if (!File.Exists(path))
            {
                Console.WriteLine($"File not found at {path}");
                return(null);
            }

            Console.WriteLine("Loading dataset...");

            var dataset = await IOOperations.LoadAsync <TestcaseBlockerDataset>(path);

            Console.WriteLine(dataset.ToString());

            return(dataset);
        }
示例#12
0
        private async void LoadDataset()
        {
            var dlg = new OpenFileDialog
            {
                Filter = "Json (*.json)|*.json"
            };

            if (dlg.ShowDialog() == true)
            {
                try
                {
                    Dataset = await IOOperations.LoadAsync <TestcaseBlockerDataset>(dlg.FileName);

                    SetStatusMessage("Dataset loaded.");
                }
                catch
                {
                    Dataset = null;
                    SetStatusMessage("Loading dataset failed. Please check the data format.");
                }
            }
        }
示例#13
0
    //set the whole scene after coming from menu or from a photosphere
    private void startGame(bool resume = false)
    {
        if (!resume)
        {
            foreach (CountryObject c in CountryPopulator.countryList)
            {
                c.chosen = false;
            }
            GlobalVariables.correctGuesses = 0;
            GlobalVariables.startedPlaying = true;
            int index = Random.Range(1, CountryPopulator.countryList.Count + 1);
            GlobalVariables.correctCountry = GlobalVariables.getCountry(index);
            IOOperations.WriteToSave("Category:" + GlobalVariables.category, true, false, true);
            CountryPopulator.setUpHint(GlobalVariables.correctCountry, GlobalVariables.category);
        }
        else
        {
            CountryPopulator.setUpHint(GlobalVariables.correctCountry, GlobalVariables.category);
            GlobalVariables.resume = false;
            photosphered           = false;
        }

        guessTimer = 0f;
    }
示例#14
0
 /// <summary>
 /// Конструктор. Создает ОМК1 согласно переданному коду. В случае если переданный код
 /// соответствует команде другого типа конструктор вызывает исключение ArgumentException.
 /// </summary>
 /// <exception cref="ArgumentException">
 /// В конструктор передан код соответствующий другому типу микрокоманды
 /// </exception>
 /// <param name="source">Исходный код микрокоманды</param>
 public OperationalMicrocommand1(ushort source)
     : base(source)
 {
     AluOutputOperation = (AluOutputAcceptor)(Source & 0x0007);
     Halt = ((Source >> 3) & 0x0001) > 0;
     NZRegistersValueOperation = (NZRegistersValueOperationType)((Source >> 4) & 0x0003);
     CarryRegisterValueOperation = (CarryRegisterValueOperationType)((Source >> 6) & 0x0003);
     IOOperation = (IOOperations)((Source >> 8) & 0x000F);
     if (((Source >> 14) & 0x0003) != 1)
         throw new ArgumentException("Unknown command type", "source");
 }
        static void Main(string[] args)
        {
            IStringOperations stringObj = new StringOperations();
            IIOOperations     ioObj     = new IOOperations();

            //Requirement 1
            try
            {
                Console.WriteLine("Enter string to count the average length of words strating with a or A");
                string stringForAvg = Console.ReadLine();
                if (!string.IsNullOrEmpty(stringForAvg))
                {
                    double avg = stringObj.AverageWordsLength(stringForAvg, new string[] { "a", "A" });
                    ioObj.WriteToTextFile(new List <string> {
                        "Input string:" + stringForAvg,
                        "",
                        "Average:" + avg.ToString()
                    }, "average_length_of_words_starting_with_a.txt");
                    Console.WriteLine("Result has been saved in average_length_of_words_starting_with_a.txt file");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Average Block:" + ex.Message);
            }
            Console.ReadLine();
            //Requirement 2
            try
            {
                Console.WriteLine("Enter string to words starting with b or B and containing e or E");
                string stringForWords = Console.ReadLine();
                if (!string.IsNullOrEmpty(stringForWords))
                {
                    List <string> value = stringObj.CountofWordsStartingWith(stringForWords, new string[] { "b", "B" }, new string[] { "e", "E" });
                    ioObj.WriteToTextFile(value, "count_of_e_in_words_starting_with_b.txt");
                    Console.WriteLine("Result has been saved in count_of_e_in_words_starting_with_b.txt file");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Finding e in words:" + ex.Message);
            }
            Console.ReadLine();
            //Requirement 3
            try
            {
                Console.WriteLine("Enter string to find longest word starting with a or b or c");
                string stringForLongestWord = Console.ReadLine();
                if (!string.IsNullOrEmpty(stringForLongestWord))
                {
                    int longest = stringObj.LongestLengthWord(stringForLongestWord, new string[] { "a", "b", "c" });
                    ioObj.WriteToTextFile(new List <string> {
                        longest.ToString()
                    }, "longest_words_starting_with_abc.txt");
                    Console.WriteLine("Result has been saved in longest_words_starting_with_abc.txt file");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Longest word block:" + ex.Message);
            }
            Console.ReadLine();
            //Requirement 4
            try
            {
                Console.WriteLine("Enter string to find sequence starting with c or C and following word starting with a or A");
                string stringForWordSequence = Console.ReadLine();
                if (!string.IsNullOrEmpty(stringForWordSequence))
                {
                    int sequence = stringObj.CountSequenceofWords(stringForWordSequence, new string[] { "c", "C" }, new string[] { "a", "A" });
                    ioObj.WriteToTextFile(new List <string> {
                        sequence.ToString()
                    }, "count_of_sequence_of_words_starting_withs_c_and_a.txt");
                    Console.WriteLine("Result has been saved in count_of_sequence_of_words_starting_withs_c_and_a.txt file");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Sequence of words block:" + ex.Message);
            }
            Console.Read();
        }
示例#16
0
        public static async Task RunOptimization(TestcaseBlockerDataset dataset)
        {
            if (dataset is null)
            {
                Console.WriteLine("Cannot run optimization for an empty dataset. First generate or load a dataset.");
                return;
            }

            var debugOutput = true;

            Console.Write("Suppress output information for each generation (y)? ");
            if (Console.ReadLine().ToLower() == "y")
            {
                debugOutput = false;
            }

            var watch = new Stopwatch();

            watch.Start();

            var optimizer = new Optimizer(dataset);

            if (debugOutput)
            {
                optimizer.ChromosomeEvaluated += Optimizer_ChromosomeEvaluated;
                optimizer.GenerationEvaluated += Optimizer_GenerationEvaluated;
            }
            else
            {
                optimizer.GenerationEvaluated += Optimizer_GenerationProgress;
            }
            var result = optimizer.Optimize();

            var duration = TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds);

            watch.Stop();

            var resolvedBlockers = string.Join(",", result.ResolvedBlockers.Select(x => x.Name).ToList());

            if (resolvedBlockers.Length > 100)
            {
                resolvedBlockers = resolvedBlockers.Substring(0, 97) + "...";
            }

            var resolvedTestcases = string.Join(",", result.ResolvedTestcases.Select(x => x.Id).ToList());

            if (resolvedTestcases.Length > 100)
            {
                resolvedTestcases = resolvedTestcases.Substring(0, 97) + "...";
            }

            var resolvedTestcasesIncludingUnblocked = string.Join(",", result.ResolvedTestcasesIncludingUnblocked.Select(x => x.Id).ToList());

            if (resolvedTestcasesIncludingUnblocked.Length > 100)
            {
                resolvedTestcasesIncludingUnblocked = resolvedTestcasesIncludingUnblocked.Substring(0, 97) + "...";
            }

            Console.WriteLine();
            Console.WriteLine($"Duration                      : {duration.ToString()} (including output)");
            Console.WriteLine($"Best solution fitness         : {result.Fitness}");
            Console.WriteLine($"Resolved Blockers             : ({result.NumberOfResolvedBlockers}/{result.Cost}) [{resolvedBlockers}]");
            Console.WriteLine($"Resolved Testcases            : ({result.NumberOfResolvedTestcases}/{result.Value}) [{resolvedTestcases}]");
            Console.WriteLine($"Resolved Testcases w/unblocked: ({result.NumberOfResolvedTestcasesIncludingUnblocked}/{result.ValueIncludingUnblocked}) [{resolvedTestcasesIncludingUnblocked}]");
            Console.WriteLine();
            Console.Write("Save result (y|n)? ");

            var saveResult = Console.ReadLine().Trim().ToLower();

            if (saveResult == "y")
            {
                Console.Write("Enter filename without extension: ");
                string filename = Console.ReadLine();

                var path = Path.Combine(GetDataPath(), filename + ".json");

                Console.WriteLine($"Saving result to {path}");

                await IOOperations.SaveAsync <OptimizationResult>(path, result);
            }
        }