Example #1
0
        /*
         * Fill the List with newly generated facts if no known facts exist;
         * otherwise, fill with unknown facts.
         */
        void generateFactsList(ref FactsQueue facts, MathOperation oper, UserProfile userProfile)
        {
            FactsList mathFactsList = new FactsList ();

            // Determine whether to read previously generated facts or generate new facts.
            if ((System.IO.File.Exists (FactsFiles.getDailyFactsFilename (oper.operationType, false))))
            {
                readUnknownFactsFromFile (ref mathFactsList, oper);
            }
            else
            {
                generateAndStoreNewFacts (ref mathFactsList, oper, userProfile);
            }

            // Determine the number of facts and obtain a set of random numbers for displaying of the facts
            if (mathFactsList != null)
            {
                randomizeFacts (ref facts, mathFactsList);
            }
        }
Example #2
0
        /*
         * Fills the List with random numbers equivalent to the number of facts to
         * display them in a random order.
         */
        static void randomizeFacts(ref FactsQueue facts, FactsList factsList)
        {
            Random random = new Random ();
            int randomNumber;
            List<int> factsOrder = new List<int> ();

            while (factsOrder.Count () < factsList.Count ())
            {
                // Check that the number is unique.
                do
                {
                    randomNumber = random.Next (factsList.Count ());
                } while (factsOrder.Contains (randomNumber));

                factsOrder.Add (randomNumber);
            }

            // Assign the numbers to a queue to display them in a random order.
            facts = new FactsQueue (factsOrder.Count ());
            foreach (int index in factsOrder)
            {
                facts.Enqueue (factsList[factsOrder[index]]);
            }
        }
Example #3
0
        /*
         * Read unmastered facts from the file.
         */
        static void readUnknownFactsFromFile(ref FactsList mathFactsList, MathOperation operation)
        {
            try
            {
                String[] numbers = System.IO.File.ReadAllLines (FactsFiles.getDailyFactsFilename (operation.operationType,
                    false));

                Fact newFact = new Fact ();
                newFact.operation = operation;

                for (int index = 0; index < numbers.Count (); ++index)
                {
                    newFact.leftNum = System.Convert.ToInt32 (numbers[index++]);

                    if (numbers.Count () != 0)
                    {
                        newFact.rightNum = System.Convert.ToInt32 (numbers[index]);
                        mathFactsList.Add (newFact);
                    }
                }
            }
            catch (Exception e)
            {
                if (e.InnerException is System.IO.FileNotFoundException)
                {
                    MessageBox.Show ("The file with your unmastered facts could not be found.");
                    return;
                }
                else
                {
                    MessageBox.Show ("There was a problem reading the file with your unmastered facts.");
                    Application.Exit ();
                }
            }
        }
Example #4
0
        /*
         * Generate and stores the facts.
         */
        static void generateAndStoreNewFacts(ref FactsList factsList, MathOperation operation, UserProfile userProfile)
        {
            Fact newFact;
            newFact.operation = operation;
            MathOperationTypeEnum operationType = operation.operationType;

            // Generate facts starting from 0 to the max number.
            for (int i = 0; i <= userProfile.maxFactNumbers[System.Convert.ToInt16 (operation.operationType)]; ++i)
            {
                for (int j = 0; j <= userProfile.maxFactNumbers[System.Convert.ToInt16 (operation.operationType)]; ++j)
                {
                    if (operationType == MathOperationTypeEnum.ADDITION ||
                         operationType == MathOperationTypeEnum.MULTIPLICATION)
                    {
                        newFact.leftNum = i;
                        newFact.rightNum = j;
                        factsList.Add (newFact);
                    }

                    // Don't allow division by 0 or results with remainders for division facts.
                    else if (i >= j && (operationType == MathOperationTypeEnum.SUBTRACTION ||
                            (operationType == MathOperationTypeEnum.DIVISION && j != 0 && (i % j == 0))))
                    {
                        newFact.leftNum = i;
                        newFact.rightNum = j;
                        factsList.Add (newFact);
                    }
                }
            }
        }