Exemplo n.º 1
0
        public Node GetCurNode(HashSet <Flow> checkedFlows, Bvr curBvr)
        {
            Node GetNodeAvoidStackOverflow(int i)
            {
                if (nodes[i] is FlowNode flowNode)
                {
                    // Avoides stack overflow
                    if (checkedFlows.Contains(flowNode.flow))
                    {
                        return(null);
                    }

                    if (nodes[i].condition())
                    {
                        return(nodes[i]);
                    }
                }
                else if (nodes[i].condition())
                {
                    return(nodes[i]);
                }

                return(null);
            }

            // When current Bvr is Waiting
            if (curBvr != null && curBvr.IsWait && curBvr.GetCurState() != null)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].forceRun)
                    {
                        var node = GetNodeAvoidStackOverflow(i);
                        if (node != null)
                        {
                            return(node);
                        }
                    }
                }
                return(waitingNode);
            }
            // When current Bvr is not Waiting
            else
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    var node = GetNodeAvoidStackOverflow(i);
                    if (node != null)
                    {
                        return(node);
                    }
                }
                return(null);
            }
        }