コード例 #1
0
        public void BuildFinalPattern(List <string> pattern, List <string> bingoCard, string ip)
        {
            List <string> finalNumbersList       = new List <string>(); //this will end up being the values to put into Fo.txt on the desired server
            List <int>    patternIndexes         = new List <int>();    //location in patternList of the elements the user checked
            int           patternIndexesCount    = 0;
            int           remainingIndexesNeeded = 0;
            int           totalNumsOnCard        = 30;
            Random        r = new Random();

            //Only grab the idexes that are not empty
            foreach (string s in pattern)
            {
                if (s.Equals(""))
                {
                    continue;
                }
                else
                {
                    patternIndexes.Add(Int32.Parse(s) - 1);//convert strings to ints, subtract 1 because checkbox values are not zero based
                }
            }

            patternIndexesCount    = patternIndexes.Count;                  //how many numbers are in the users pattern
            remainingIndexesNeeded = totalNumsOnCard - patternIndexesCount; //how many more numbers we need to fill the bingo card to a total of 30 numbers

            //grab the elements from bingcard that reside in indexes based off of patternIndexes results
            foreach (int s in patternIndexes)
            {
                finalNumbersList.Add(bingoCard[s]);//Add users pattern to this list
            }

            //fill remaining elements with random numbers between 1 and 75
            //cannot be duplicate numbers
            for (int i = 0; i < remainingIndexesNeeded; i++)
            {
                int n = r.Next(1, 75);
                //check if the number generated is already a number in bingo card OR a number in final numbers list
                if (bingoCard.Contains(n.ToString()) || finalNumbersList.Contains(n.ToString()))
                {
                    i--;//So this check never happened according to the iteration
                    continue;
                }
                else
                {
                    finalNumbersList.Add(n.ToString());
                }
            }

            //TODO:Update Fo.txt on the server
            ForceController.EditFOtxtOnHydra(finalNumbersList, ip);
            //ForceController.EchoIntoFO(finalNumbersList, ip);
        }
コード例 #2
0
        public string ValidateNumbers(List <string> pattern, string ip)
        {
            string errDuplicate    = "A duplicate number exists in your pattern. Try again please.";
            string errOutOfBounds  = "A number in your pattern is outside of the acceptable boundries (must be >= 0 and <= 75). Try again please.";
            string errNotANumber   = "Only numbers are accepted and 1 or more values. Try again please.";
            string success         = "Your numbers have been successfully saved! May the force be with your EPS!";
            string finalResult     = "";
            var    hashset         = new HashSet <string>();//for checking dups
            bool   passesAllChecks = true;

            //Extract distinct values from the pattern list and save to a new list (safeguard against user putting in dups).
            List <string> distinctPattern = pattern.Distinct().ToList();

            try
            {
                //Validation
                foreach (string s in distinctPattern)
                {
                    //check number boundries
                    if (Int32.Parse(s) >= 0 && Int32.Parse(s) <= 75)
                    {
                        //check for duplicates
                        if (hashset.Add(s))
                        {
                            //passed duplicate check and bounds check
                            passesAllChecks = true;
                        }
                        else
                        {
                            //This shouldnt trigger because duplicates are removed before the loop. But its here as a back up check.
                            Trace.WriteLine(errDuplicate);
                            passesAllChecks = false;
                            finalResult     = errDuplicate;
                        }
                    }
                    else
                    {
                        Trace.WriteLine(errOutOfBounds);
                        passesAllChecks = false;
                        finalResult     = errOutOfBounds;
                        break;// do not continue the foreach
                    }
                }
            }
            catch
            {
                Trace.WriteLine(errNotANumber);
                passesAllChecks = false;
                finalResult     = errNotANumber;
            }

            //Update Fo.txt on the server, if the list passed all validation
            if (passesAllChecks == true)
            {
                ForceController.EditFOtxtOnHydra(distinctPattern, ip);
                ForceController.EchoIntoFO(distinctPattern, ip);
                finalResult = success;
            }

            return(finalResult);
        }