コード例 #1
0
        public void TestGetBannedWords()
        {
            WordListManager listManager = new WordListManager(acceptedWordsPath, bannedWordsPath, 3, 8);
            List <string>   bannedWords = listManager.GetBannedWords();

            Assert.AreEqual(bannedWords[0], "ASS");
            Assert.AreEqual(bannedWords[bannedWords.Count - 1], "QUICKIE");
        }
コード例 #2
0
        public void TestGetAcceptedWords()
        {
            WordListManager listManager = new WordListManager(acceptedWordsPath, bannedWordsPath, 3, 8);
            Word            test1       = new Word("ABANDON", 10);
            int             complexity1 = test1.GetComplexity();
            Word            test2       = new Word("ZOOM", 10);
            int             complexity2 = test2.GetComplexity();

            List <string>[] acceptedWords = listManager.GetAcceptedWords();
            Assert.IsTrue(acceptedWords[complexity1].Contains("ABANDON"));
            Assert.IsTrue(acceptedWords[complexity2].Contains("ZOOM"));
        }
コード例 #3
0
        /// <summary>
        /// Creates new file and writes generated gameplay into it
        /// </summary>
        /// <param name="targetFilePath">Path to the file being written to</param>
        /// <param name="validPath">Valid words list file path</param>
        /// <param name="bannedPath">Banned words list file path</param>
        /// <param name="allModel">Project configuration</param>
        public void CreateGeneratedFile(string targetFilePath, string validPath, string bannedPath, AllModelsModel allModel)
        {
            List <PrizeLevelModel> prizeLevels = new List <PrizeLevelModel>(allModel.PrizeLevelsModel.PrizeLevelList);
            List <DivisionModel>   divisions   = new List <DivisionModel>(allModel.DivisionsModel.DivisionList);
            GameSetupModel         gameModel   = allModel.GameSetupModel;

            PlayGenerator generator = new PlayGenerator(validPath, bannedPath);
            StringBuilder gameplay  = new StringBuilder();

            int        numPermutations = allModel.DivisionsModel.NumPermutations;
            List <int> complexities    = new List <int>();

            LogWriter.GetInstance().WriteLog("Generating complexities");

            // sets complexities for entire generation
            if (!allModel.PrizeLevelsModel.Randomize)
            {
                foreach (PrizeLevelModel currentPrizeLevel in prizeLevels)
                {
                    complexities.Add(currentPrizeLevel.UniqueLetterCount);
                }
                LogWriter.GetInstance().WriteLog("Finished non-random complexities");
            }

            for (int i = 0; i < numPermutations; i++)
            {
                // creates new complexities list for each permutation
                if (allModel.PrizeLevelsModel.Randomize)
                {
                    LogWriter.GetInstance().WriteLog("Generating random complexities");
                    complexities.Clear();
                    WordListManager lists = new WordListManager(validPath, bannedPath, 1, 30);
                    List <int>      potentialComplexities = new List <int>();
                    for (int complexityIndex = lists.GetLeastComplexCount(); complexityIndex < lists.GetMostComplexCount(); complexityIndex++)
                    {
                        if (lists.HasComplexity(complexityIndex))
                        {
                            potentialComplexities.Add(complexityIndex);
                        }
                    }
                    potentialComplexities.Shuffle();

                    foreach (PrizeLevelModel currentPrizeLevel in prizeLevels)
                    {
                        int    seed = (int)((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) % Int32.MaxValue);
                        Random rand = new Random(seed);
                        int    nextComplexityIndex = rand.Next(0, potentialComplexities.Count);
                        int    nextComplexityValue = potentialComplexities[nextComplexityIndex];
                        potentialComplexities.Remove(nextComplexityValue);

                        complexities.Add(nextComplexityValue);
                    }
                    LogWriter.GetInstance().WriteLog("Finished randomized complexities");
                }

                LogWriter.GetInstance().WriteLog("Creating WordManager");
                WordManager manager = new WordManager(prizeLevels.Count, complexities, validPath, bannedPath);
                LogWriter.GetInstance().WriteLog("Finished creating WordManager");
                foreach (DivisionModel currentDivision in divisions)
                {
                    LogWriter.GetInstance().WriteLog("Generating gameplay");
                    string winPermutation = generator.GenerateGameplay(prizeLevels, currentDivision, gameModel, complexities, prizeLevels.IndexOf(currentDivision.PrizeLevel), manager, allModel.PrizeLevelsModel.Randomize);
                    gameplay.Append(winPermutation);
                    LogWriter.GetInstance().WriteLog("Finished generating gameplay");
                }
                // lose division
                DivisionModel loss = new DivisionModel(allModel.DivisionsModel);
                loss.Multiplier = 0;
                gameplay.Append(generator.GenerateGameplay(prizeLevels, loss, gameModel, complexities, -1, manager, allModel.PrizeLevelsModel.Randomize));
            }

            File.WriteAllText(targetFilePath, gameplay.ToString());
        }
コード例 #4
0
        public void TestGetLeastComplexWord()
        {
            WordListManager listManager = new WordListManager(complexityWordsPath, bannedWordsPath, 3, 7);

            Assert.AreEqual(listManager.GetLeastComplexCount(), 3);
        }
コード例 #5
0
 public void TestListManagerConstructor()
 {
     // verifies that files exists
     WordListManager listManager = new WordListManager(acceptedWordsPath, bannedWordsPath, 3, 5);
 }