コード例 #1
0
        /// <summary>
        /// Find a forced win, if available.  A forced win occurs from a
        /// particular node when the all of the Children of a child node are either
        /// terminals or forced wins.
        /// </summary>
        /// <param name="node"> The node from which to find a forced win. </param>
        public virtual LetterNode ForcedWin(LetterNode node)
        {
            LetterNode winningChild = null;

            foreach (LetterNode child in node.Children().Values)
            {
                if (!child.LeafNode)
                {
                    winningChild = child;
                    foreach (LetterNode grandChild in child.Children().Values)
                    {
                        if (!(grandChild.LeafNode || (ForcedWin(grandChild) != null)))
                        {
                            winningChild = null;
                            break;
                        }
                    }
                }

                if (winningChild != null)
                {
                    break;
                }
            }

            return(winningChild);
        }
コード例 #2
0
        /// <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);
        }