Пример #1
0
            public void CheckForLeaves(
                ActionButtonNode parent,
                List <ActionOption> optionsLeft,
                Actor actor,
                CheckInOptionLeafAction checkIn,
                DeadEndOptionLeafAction deadEnd)
            {
                if (optionsLeft.Count == 0 && parent.PathLengthToRoot == ActionOptions.Count)                 //this is a leaf state
                {
                    checkIn(parent);
                    return;
                }

                ActionOption nextOne = optionsLeft.First();

                optionsLeft.Remove(nextOne);

                //here there could be a check for 0 choices on the options, and a way to "get a reason explanation" for the pat dead end
                if (nextOne.GetChoices(actor, this).Count == 0)
                {
                    deadEnd(parent, nextOne.LastNoChoiceReason);
                    return;
                }

                foreach (IActionOptionChoice choice in nextOne.GetChoices(actor, this))
                {
                    ActionButtonNode child = new ActionButtonNode();
                    child.label = choice.ValueLabel();

                    //imitate the next choice being chosen, so GetChoices works correctly...
                    nextOne.chosenChoice = choice;
                    CheckForLeaves(child, optionsLeft.ToList(), actor, checkIn, deadEnd);
                    nextOne.chosenChoice = null;
                }
            }
Пример #2
0
            public bool CanFillOptions(Actor actor)
            {
                ActionButtonNode root = new ActionButtonNode();

                root.label = ValueLabel();
                bool canFill = false;

                CheckInOptionLeafAction checkin = (leaf) => {
                    Debug.Log("found a leaf!: " + leaf.label);
                    //any leaf will do...
                    canFill = true;
                };

                DeadEndOptionLeafAction deadend = (leaf, reason) => {
                    Debug.Log("Dead end: " + leaf.label);
                    Debug.Log("reason: " + reason);
                };


                CheckForLeaves(root, ActionOptions.ToList(), actor, checkin, deadend);

                return(canFill);
            }