Ejemplo n.º 1
0
        public ResultContainer <string> Play(string word)
        {
            StatusEnum status = StatusEnum.Continue;

            Node <string> node = treeBuilder.Search(word, root);

            // Player give a word that is terminal
            if (IsLoss(node, word))
            {
                status = StatusEnum.MachineWin;
            }
            else
            {
                // Evaluate from the node used by the player, stating playing as a machine.
                IValueContainer <string, int> value = decisionMaker.Evaluate(node, 10, false, word.Length <= MIN_LOSS_LENGTH);

                // If this happend, the player has lost because a terminal word was found but was less than MIN_LOSS_LENGTH character length.
                if (value.MinusInfinity)
                {
                    status = StatusEnum.MachineWin;
                }
                else
                {
                    // This is the word selected by the decision maker.
                    // Get the next letter to play.
                    word = value.Value.Substring(0, word.Length + 1);

                    // Can search from this node because value must be a word that extends the one of the node.
                    node = treeBuilder.Search(word, node);

                    if (IsLoss(node, word))
                    {
                        status = StatusEnum.PlayerWin;
                    }
                }
            }

            return(new ResultContainer <string>
            {
                Element = word,
                Status = status
            });
        }