/// <summary>
        /// Find the longest word reachable from the specified node.
        /// </summary>
        /// <param name="node"> The node from which to find the longest word. </param>
        public virtual LetterNode LongestWord(LetterNode node)
        {
            LetterNode longestChild = null;

            foreach (LetterNode child in node.Children().Values)
            {
                if ((longestChild == null) || (child.MaxLength() > longestChild.MaxLength()))
                {
                    longestChild = child;
                }
            }

            return(longestChild);
        }
Exemplo n.º 2
0
        /// <summary>
        /// A test harness for the LetterNode class.
        /// </summary>
        /// <param name="args"> The command line arguments passed in. </param>
        public static void TestLetterNode(string[] args)
        {
            if (args.Length > 0)
            {
                LetterNode node = new LetterNode(args[0]);

                for (int i = 1; i < args.Length; i++)
                {
                    node.AddWord(args[i]);
                }

                Console.Write("Total words = " + node.LeafNodeCount());
                Console.Write("Maximum word length = " + node.MaxLength());
            }
            else
            {
                Console.Write("Usage:  GhostGame " + typeof(LetterNode).FullName + " <word-list>");
            }
        }