/// <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); } } }
/// <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; } }
/// <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; } }
/// <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); }
/// <summary> /// Set the value of one of the buttons in the grid with a letter /// </summary> /// <param name="count">The 1-D position of the button</param> /// <param name="letter">The new letter value</param> public void SetButtonValue(int count, LetterUtil.Letter letter) { SetButtonValue(count % SizeX, count / SizeX, letter); }
/// <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; }
/// <summary> /// Key press event handler. When the user's mouse is focused on the button and the user presses a button this is called /// to be an easy way to set the selected letter on the button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void keyDown(object sender, KeyEventArgs e) { if (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) { switch (e.KeyCode) { case Keys.A: SelectedLetter = LetterUtil.Letter.A; this.Text = "A"; break; case Keys.B: SelectedLetter = LetterUtil.Letter.B; this.Text = "B"; break; case Keys.C: SelectedLetter = LetterUtil.Letter.C; this.Text = "C"; break; case Keys.D: SelectedLetter = LetterUtil.Letter.D; this.Text = "D"; break; case Keys.E: SelectedLetter = LetterUtil.Letter.E; this.Text = "E"; break; case Keys.F: SelectedLetter = LetterUtil.Letter.F; this.Text = "F"; break; case Keys.G: SelectedLetter = LetterUtil.Letter.G; this.Text = "G"; break; case Keys.H: SelectedLetter = LetterUtil.Letter.H; this.Text = "H"; break; case Keys.I: SelectedLetter = LetterUtil.Letter.I; this.Text = "I"; break; case Keys.J: SelectedLetter = LetterUtil.Letter.J; this.Text = "J"; break; case Keys.K: SelectedLetter = LetterUtil.Letter.K; this.Text = "K"; break; case Keys.L: SelectedLetter = LetterUtil.Letter.L; this.Text = "L"; break; case Keys.M: SelectedLetter = LetterUtil.Letter.M; this.Text = "M"; break; case Keys.N: SelectedLetter = LetterUtil.Letter.N; this.Text = "N"; break; case Keys.O: SelectedLetter = LetterUtil.Letter.O; this.Text = "O"; break; case Keys.P: SelectedLetter = LetterUtil.Letter.P; this.Text = "P"; break; case Keys.Q: SelectedLetter = LetterUtil.Letter.Q; this.Text = "Q"; break; case Keys.R: SelectedLetter = LetterUtil.Letter.R; this.Text = "R"; break; case Keys.S: SelectedLetter = LetterUtil.Letter.S; this.Text = "S"; break; case Keys.T: SelectedLetter = LetterUtil.Letter.T; this.Text = "T"; break; case Keys.U: SelectedLetter = LetterUtil.Letter.U; this.Text = "U"; break; case Keys.V: SelectedLetter = LetterUtil.Letter.V; this.Text = "V"; break; case Keys.W: SelectedLetter = LetterUtil.Letter.W; this.Text = "W"; break; case Keys.X: SelectedLetter = LetterUtil.Letter.X; this.Text = "X"; break; case Keys.Y: SelectedLetter = LetterUtil.Letter.Y; this.Text = "Y"; break; case Keys.Z: SelectedLetter = LetterUtil.Letter.Z; this.Text = "Z"; break; } } }