示例#1
0
        public void GreedyAlgorithm()
        {
            //Console.WriteLine(m_Grid.ToString());
            List <Word> potentialWords = m_Grid.GenPossiblePositionsV3(m_CharMappedWords);

            //Console.WriteLine(m_Grid.ToString());
            if (potentialWords.Count == 0)
            {
                CrozzleApplication.Crozzle currentCrozle = new CrozzleApplication.Crozzle(m_Crozzle.CrozzlePath, m_Crozzle.Configuration, m_Crozzle.WordList);
                currentCrozle.ConfigurationPath = m_Crozzle.ConfigurationPath;
                currentCrozle.WordListPath      = m_Crozzle.WordListPath;
                currentCrozle.Rows    = m_Crozzle.Rows;
                currentCrozle.Columns = m_Crozzle.Columns;


                CrozzleApplication.WordDataList wordDataList;
                CrozzleApplication.WordDataList.TryParse(m_Grid.ToWordData(), currentCrozle, out wordDataList);
                currentCrozle.WordDataList = wordDataList;
                currentCrozle.CreateCrozzleRows(wordDataList);
                currentCrozle.CreateCrozzleColumns(wordDataList);
                currentCrozle.Validate();

                if (currentCrozle.CrozzleValid && currentCrozle.CrozzleScore() > m_Crozzle.CrozzleScore())
                {
                    m_Crozzle = currentCrozle;
                }
            }
            else
            {
                if (m_Grid.IsEmpty)
                {
                    foreach (Word word in potentialWords)
                    {
                        Node childNode = Copy();
                        childNode.m_Grid.InsertWord(word);
                        // Remove inserted word
                        for (int charIndex = 0; charIndex < word.Length; charIndex++)
                        {
                            childNode.m_CharMappedWords[word[charIndex].Value].Remove(word.Value);
                        }
                        m_ChildNode.Add(childNode);
                        childNode.GreedyAlgorithm();
                    }
                }
                else
                {
                    Node childNode = Copy();
                    Word word      = potentialWords[0];
                    childNode.m_Grid.InsertWord(word);
                    // Remove inserted word
                    for (int charIndex = 0; charIndex < word.Length; charIndex++)
                    {
                        childNode.m_CharMappedWords[word[charIndex].Value].Remove(word.Value);
                    }
                    m_ChildNode.Add(childNode);
                    childNode.GreedyAlgorithm();
                }
            }
        }
示例#2
0
        public Node(CrozzleApplication.Crozzle aCrozzle)
        {
            m_Crozzle = aCrozzle;
            m_Grid    = new Grid(aCrozzle.Rows, aCrozzle.Columns);
            m_Words   = new List <string>(aCrozzle.WordList.List);

            // Map each word to all the alphabets it has
            m_CharMappedWords = new Dictionary <char, List <string> >();
            foreach (char Alphabet in m_Alphabets)
            {
                m_CharMappedWords.Add(Alphabet, new List <string>());
            }
            CharMapWords();
            m_ChildNode = new List <Node>();
            m_Grid.AddIntersectingCharWeight(aCrozzle.Configuration.IntersectingPointsPerLetter);
        }