Beispiel #1
0
        /// <summary>
        /// Search this node for all partial matches of a word (up to the value of WORD_SEARCH_LIMIT) and append them to the list parameter
        /// </summary>
        /// <param name="wordEnum">The partial word to match</param>
        /// <param name="solns">The list of solutions to be added to</param>
        public void WordSearch(CharEnumerator wordEnum, List <String> solns)
        {
            if (!wordEnum.MoveNext())
            {
                if (_isWord)
                {
                    solns.Add(this.ToString());
                    if (solns.Count >= WORD_SEARCH_LIMIT)
                    {
                        return;
                    }
                }

                foreach (DictNode n in Children)
                {
                    n.WordSearch(solns);
                    if (solns.Count >= WORD_SEARCH_LIMIT)
                    {
                        return;
                    }
                }
                return;
            }

            LetterUtil.Letter letter = LetterUtil.GetLetter(wordEnum.Current);
            foreach (DictNode n in Children)
            {
                if (letter == n.LetterEnum)
                {
                    n.WordSearch(wordEnum, solns);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor used when initialising an anagram with a given word
        /// </summary>
        /// <param name="word">The word to initialise with</param>
        /// <param name="window">A reference to the parent form of this grid</param>
        public LetterGrid(String word, MainWindow window) : this(GRID_MAX_X, word.Length / GRID_MAX_X + (((word.Length % GRID_MAX_X) == 0) ? 0 : 1), window)
        {
            Options = new GameOptions(word.Length);

            CharEnumerator charEnum = word.GetEnumerator();
            int            count    = 0;

            while (charEnum.MoveNext())
            {
                SetButtonValue(count++, LetterUtil.GetLetter(charEnum.Current));
            }

            if (!Options.IsMaxAnagramLength)
            {
                SetIsAddLetter(count, true);
            }

            foreach (LetterButton[] buttons in Buttons)
            {
                foreach (LetterButton button in buttons)
                {
                    button.Sync(this);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Event handler for when the quick enter menu item is clicked. This is when you enter a series of letters to be displayed in the grid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QuickGridEnterMenu_Click(object sender, EventArgs e)
        {
            String result = Interaction.InputBox("Enter the letters in order with spaces in between them", "Quick Letter Entry", String.Empty);

            string[] letters = result.Split(' ');
            switch (_gridIndex)
            {
            case 0:
                throw new NotImplementedException();

            case 1:
                if (letters.Length < 16)
                {
                    if (MessageBox.Show("Not enough letters entered", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
                        == System.Windows.Forms.DialogResult.Retry)
                    {
                        QuickGridEnterMenu_Click(null, null);
                    }
                    return;
                }

                for (int i = 0; i < 16; i++)
                {
                    _gameGrid.SetButtonValue(i, LetterUtil.GetLetter(letters[i][0]));
                }
                break;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Get the letter enum representation for this node. If this is a multi-letter node, it will
 /// return the current position in the di/trigram
 /// </summary>
 /// <returns>The letter in enum form</returns>
 public LetterUtil.Letter GetLetter()
 {
     if (IsDigram())
     {
         return(LetterUtil.SplitDigram(Letter, UseCount));
     }
     else
     {
         return(Letter);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parentGrid">The parent grid for the node</param>
        /// <param name="letter">The letter enum used for the node</param>
        /// <param name="isMandatory">Is the node required to be used in word searches</param>
        /// <param name="restriction">The restrictions on the use of this node</param>
        public GridNode(LetterGrid parentGrid, LetterUtil.Letter letter, bool isMandatory, PositionRestriction restriction)
        {
            ParentGrid    = parentGrid;
            Letter        = letter;
            AdjacentNodes = new List <GridNode>();
            IsMandatory   = isMandatory;
            Restriction   = restriction;
            LetterLength  = LetterUtil.GetLetterLength(Letter);

            if (ParentGrid.Options.IsAnagram)
            {
                IsMandatory = true;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Constructor used when there is no parent node, i.e. the root of the tree
        /// </summary>
        /// <param name="subword">The enumeration of the word to populate the tree</param>
        /// <param name="depth">The depth of the node</param>
        /// <param name="parent">The node immediately above this node in the tree</param>
        public DictNode(CharEnumerator subword, int depth, TreeTraverse parent) : base(parent)
        {
            _depth     = depth;
            Letter     = subword.Current;
            LetterEnum = LetterUtil.GetLetter(Letter);

            if (subword.MoveNext())
            {
                Children.Add(new DictNode(subword, _depth + 1, this));
                _isWord = false;
            }
            else
            {
                _isWord = true;
            }
        }
Beispiel #7
0
 /// <summary>
 /// Add a file to be loaded to the dictionary. Don't call from the main thread, it's not instantaneous.
 /// </summary>
 /// <param name="file">The path to the file to be loaded</param>
 private void AddFile(String file)
 {
     using (FileStream fs = File.OpenRead(file))
     {
         using (StreamReader sr = new StreamReader(fs))
         {
             String line;
             while ((line = sr.ReadLine()) != null)
             {
                 line = line.Trim().ToLowerInvariant();
                 if (!LetterUtil.ContainsInvalidLetters(line))
                 {
                     Tree.AddWord(line);
                 }
             }
         }
     }
 }
Beispiel #8
0
        /// <summary>
        /// Convenience method for getting the text to be displayed on the button
        /// </summary>
        /// <param name="button">The button which the text will be displayed on</param>
        /// <returns>The text that should be shown on the button</returns>
        public static String GetText(LetterButton button)
        {
            if (button.IsAddLetter)
            {
                return("+");
            }

            String text = LetterUtil.ConvertToString(button.SelectedLetter);

            switch (button.Restriction)
            {
            case PositionRestriction.START:
                text += "-";
                break;

            case PositionRestriction.END:
                text = "-" + text;
                break;
            }

            return(text);
        }
Beispiel #9
0
        /// <summary>
        /// Perform a partial word search. This will find all words (up to a certain number) that start with the first parameter.
        /// </summary>
        /// <param name="partialWord">The start of the words to search for</param>
        /// <returns>A list of matched words</returns>
        public List <String> WordSearch(String partialWord)
        {
            List <String> solns = new List <string>();

            CharEnumerator wordEnum = partialWord.GetEnumerator();

            if (!wordEnum.MoveNext())
            {
                return(solns);
            }

            LetterUtil.Letter letter = LetterUtil.GetLetter(wordEnum.Current);
            foreach (DictNode n in Children)
            {
                if (letter == n.LetterEnum)
                {
                    n.WordSearch(wordEnum, solns);
                }
            }

            return(solns);
        }
Beispiel #10
0
 /// <summary>
 /// The string representation of this node. (Is just the letter)
 /// </summary>
 /// <returns>The letter of the node</returns>
 public override String ToString()
 {
     return(LetterUtil.ConvertToString(Letter));
 }
Beispiel #11
0
 /// <summary>
 /// Set the value of one of the buttons in the grid with a letter
 /// </summary>
 /// <param name="x">The x position of the button</param>
 /// <param name="y">The y position of the button</param>
 /// <param name="letter">The new letter value</param>
 public void SetButtonValue(int x, int y, LetterUtil.Letter letter)
 {
     Buttons[y][x].Text           = LetterUtil.ConvertToString(letter);
     Buttons[y][x].SelectedLetter = letter;
 }