예제 #1
0
        private List <string> CheckWordExist(WordInfo wordInfo, WordResult wordResult)
        {
            List <Word>   usedWord = wordResult.GetUsedWord();
            List <string> wordList = wordInfo.GetWordList();

            // Check if word exists
            List <string> unknownWord = new List <string>();
            bool          found;

            for (int i = 0; i < usedWord.Count(); i++)
            {
                found = false;
                for (int j = 0; j < wordList.Count(); j++)
                {
                    if (usedWord[i].GetWordContent().Equals(wordList[j]))
                    {
                        found = true;
                        break;
                    }
                }
                if (found == false)
                {
                    unknownWord.Add(usedWord[i].GetWordContent());
                    Error.AddCrozzleError(usedWord[i].GetWordContent() + ": not exist");
                }
            }
            return(unknownWord);
        }
예제 #2
0
        private void CheckWordsCombined(WordInfo wordInfo, List <string> unknownWord)
        {
            List <string> wordList = wordInfo.GetWordList();
            int           row      = GetMaxRow();
            int           column   = GetMaxColumn();

            char[,] grid = DrawGrid(row, column);
            // Check words in grid: if they combined and formed a longer word which does not record in wordlist.txt
            for (int i = 0; i < row; i++)
            {
                char[] lineOfChar = new char[column];
                for (int j = 0; j < column; j++)
                {
                    lineOfChar[j] = grid[i, j];
                }
                string   line      = new string(lineOfChar);
                char[]   separator = { SpaceSymbol };
                string[] words     = line.Split();
                for (int j = 0; j < words.Length; j++)
                {
                    if (words[j].Length == 1 || words[j].Length == 0)
                    {
                        continue;
                    }
                    if (!Search(words[j], wordList))
                    {
                        if (!Search(words[j], unknownWord))
                        {
                            Error.AddCrozzleError("row " + (i + 1) + " " + words[j] + ": 2 word placed together and formed a new word which does not exist in the word list");
                        }
                    }
                }
            }
            for (int i = 0; i < column; i++)
            {
                char[] lineOfChar = new char[row];
                for (int j = 0; j < row; j++)
                {
                    lineOfChar[j] = grid[j, i];
                }
                string   line      = new string(lineOfChar);
                char[]   separator = { SpaceSymbol };
                string[] words     = line.Split();
                for (int j = 0; j < words.Length; j++)
                {
                    if (words[j].Length == 1 || words[j].Length == 0)
                    {
                        continue;
                    }
                    if (!Search(words[j], wordList))
                    {
                        if (!Search(words[j], unknownWord))
                        {
                            Error.AddCrozzleError("column " + (i + 1) + " " + words[j] + ": 2 word placed together and formed a new word which does not exist in the word list");
                        }
                    }
                }
            }
        }
예제 #3
0
        private void CreateCrozzle()
        {
            Config configuration = new Config();

            configuration.SetConfig("configuration.txt");
            string intersectionsPerPoints    = configuration.GetIntersectingPointsPerLetter();
            string nonIntersectionsPerPoints = configuration.GetNonIntersectingPointsPerLetter();

            InitializePublicInfo(configuration);

            WordInfo wordlist = new WordInfo();

            wordlist.SetWordList("wordList.txt");
            wordlist.SetIntersectingPointsPerLetter(intersectionsPerPoints);
            wordlist.SetNonIntersectingPointsPerLetter(nonIntersectionsPerPoints);
            List <string> wlist = wordlist.GetWordList();


            // preprocess wordlist
            SIT323Crozzle.CreateCrozzle.SetPotentialValue(wlist, wordlist.GetIntersectingPointsPerLetter(), wordlist.GetNonIntersectingPointsPerLetter());
            string initialWordContent = PreProcess(wlist);

            // get initial crozzle
            CrozzlePartial initialCrozzle = GenerateInitialCrozzle(initialWordContent, wlist);

            aTimer.Start();
            SIT323Crozzle.CreateCrozzle.GenerateCrozzle(initialCrozzle);
            CrozzlePartial goodCrozzle = SIT323Crozzle.CreateCrozzle.GetBestCrozzle();

            aTimer.Stop();

            // get grid and show crozzle
            string style       = configuration.GetStyle();
            bool   uppercase   = configuration.GetUppercase();
            Grid   crozzleGrid = goodCrozzle.GetGrid();

            char[,] largeGrid = crozzleGrid.GetGrid();
            char[,] grid      = new char[PublicInfo.GetRows(), PublicInfo.GetColumns()];
            for (int i = 0; i < PublicInfo.GetRows(); i++)
            {
                for (int j = 0; j < PublicInfo.GetColumns(); j++)
                {
                    if (i + goodCrozzle.GetMinHeight() <= goodCrozzle.GetMaxHeight() && j + goodCrozzle.GetMinWidth() <= goodCrozzle.GetMaxWidth())
                    {
                        grid[i, j] = largeGrid[i + goodCrozzle.GetMinHeight(), j + goodCrozzle.GetMinWidth()];
                    }
                }
            }
            String crozzleHTML = @"<!DOCTYPE html>
                                <html>
                                <head>" + style + @"</head><body><table>";

            for (int row = 0; row < PublicInfo.GetRows(); row++)
            {
                String tr = "<tr>";
                for (int column = 0; column < PublicInfo.GetColumns(); column++)
                {
                    if (grid[row, column].CompareTo('\0') != 0)
                    {
                        tr += @"<td style='background:" + configuration.GetBgcolourNonEmptyTD();
                        if (uppercase == true)
                        {
                            tr += "'>" + grid[row, column].ToString().ToUpper() + @"</td>";
                        }
                        if (uppercase == false)
                        {
                            tr += "'>" + grid[row, column].ToString().ToLower() + @"</td>";
                        }
                    }
                    else
                    {
                        tr += @"<td style='background:" + configuration.GetBgcolourEmptyTD();
                        if (uppercase == true)
                        {
                            tr += "'>" + grid[row, column].ToString().ToUpper() + @"</td>";
                        }
                        if (uppercase == false)
                        {
                            tr += "'>" + grid[row, column].ToString().ToLower() + @"</td>";
                        }
                    }
                }
                tr += "</tr>";

                crozzleHTML += tr;
            }
            crozzleHTML += @"</table>";
            crozzleHTML += "<p>score: ";
            crozzleHTML += goodCrozzle.GetScore();
            crozzleHTML += "</p>";
            crozzleHTML += "</body></html>";
            CrozzleBrowser.DocumentText = crozzleHTML;
            ErrorBrowser.DocumentText   = " ";
        }