예제 #1
0
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            if (status == NodeStatus.STATUS_FAILURE)
            {
                SetFailuer();
                return(m_nodeStatus);
            }
        }

        BaseBTNode runningNode = computeRunningNode(m_nodes);

        if (runningNode != null)
        {
            switch (runningNode.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                break;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                break;
            }
        }

        foreach (BaseBTNode node in m_nodes)
        {
            if (node == runningNode)
            {
                continue;
            }
            switch (node.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                continue;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                continue;
            }
        }
        m_nodeStatus = NodeStatus.STATUS_FAILURE;
        return(m_nodeStatus);
    }
    private BaseBTNode m_preNode;             //始めにランダムから省くため

    public BTOnOffSelector(List <BaseBTNode> nodes, BaseBTCondition condNode = null)
    {
        m_nodes         = nodes;
        m_conditionNode = condNode;
        m_failuerNodes  = new List <BaseBTNode>();
        m_preNode       = null;
    }
예제 #3
0
    //ノード状態の評価
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            switch (status)
            {
            case NodeStatus.STATUS_SUCCESS:
                if (m_nodes[0] != m_preNode)
                {
                    m_preNode.SetFailuer();
                }
                m_nodeStatus = m_nodes[0].Evaluate();
                m_preNode    = m_nodes[0];
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                if (m_nodes[1] != m_preNode)
                {
                    m_preNode.SetFailuer();
                }
                m_nodeStatus = m_nodes[1].Evaluate();
                m_preNode    = m_nodes[1];
                return(m_nodeStatus);

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = m_preNode.Evaluate();
                return(m_nodeStatus);
            }
        }
        //ここにくるのはおかしい
        return(NodeStatus.STATUS_FAILURE);
    }
 public override void SetFailuer()
 {
     m_nodeStatus = NodeStatus.STATUS_FAILURE;
     m_preNode.SetFailuer();
     m_firstSearch = true;
     m_preNode     = m_nodes[0];
 }
예제 #5
0
 //コンストラクタ
 public BTBoolSelector(BaseBTNode trueNode, BaseBTNode falseNode, BaseBTCondition condNode)
 {
     m_nodes         = new BaseBTNode[2];
     m_nodes[0]      = trueNode;
     m_nodes[1]      = falseNode;
     m_conditionNode = condNode;
     m_preNode       = m_nodes[0];
 }
    private bool m_firstSearch; //ToEndNodeの実行が終了したときtrueになる

    public BTNTEandTEBoolSelector(BaseBTNode notToEndNodeWithTrue, BaseBTNode toEndNodeWithFalse, BTConditionNotToEnd condNode)
    {
        m_nodes         = new BaseBTNode[2];
        m_nodes[0]      = notToEndNodeWithTrue;
        m_nodes[1]      = toEndNodeWithFalse;
        m_conditionNode = condNode;
        m_preNode       = m_nodes[1];
        m_firstSearch   = true;
    }
예제 #7
0
    public override void SetFailuer()
    {
        m_nodeStatus = NodeStatus.STATUS_FAILURE;
        BaseBTNode node = computeRunningNode(m_nodes);

        if (node != null)
        {
            node.SetFailuer();
        }
    }
예제 #8
0
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            if (status == NodeStatus.STATUS_FAILURE)
            {
                SetFailuer();
                return(m_nodeStatus);
            }
        }

        BaseBTNode runningNode = computeRunningNode(m_nodes);

        if (runningNode != null)
        {
            m_isRunningNode = true;
        }

        //子ノードの処理を順番に実行
        foreach (BaseBTNode node in m_nodes)
        {
            if (m_isRunningNode)
            {
                if (node != runningNode)
                {
                    continue;
                }
                else
                {
                    m_isRunningNode = false;
                }
            }
            switch (node.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                continue;

            case NodeStatus.STATUS_FAILURE:
                m_nodeStatus = NodeStatus.STATUS_FAILURE;
                return(m_nodeStatus);

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);
            }
        }
        m_nodeStatus = NodeStatus.STATUS_SUCCESS;
        return(m_nodeStatus);
    }
    public override void SetFailuer()
    {
        m_preNode = null;
        foreach (BaseBTNode node in m_failuerNodes)
        {
            m_nodes.Add(node); //m_nodesにはないはず
        }
        m_failuerNodes.Clear();
        m_nodeStatus = NodeStatus.STATUS_FAILURE;
        BaseBTNode childNode = computeRunningNode(m_nodes);

        if (childNode != null)
        {
            childNode.SetFailuer();
        }
    }
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            if (status == NodeStatus.STATUS_FAILURE)
            {
                SetFailuer();
                return(m_nodeStatus);
            }
        }

        BaseBTNode runningNode = computeRunningNode(m_nodes);

        if (runningNode != null)
        {
            switch (runningNode.Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                break;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                return(m_nodeStatus);

            default:
                break;
            }
        }

        if (m_preNode != null)
        {
            m_failuerNodes.Add(m_preNode);
            m_nodes.Remove(m_preNode);
        }
        while (m_nodes.Count > 0)
        {
            int selectNode = UnityEngine.Random.Range(0, m_nodes.Count);
            switch (m_nodes[selectNode].Evaluate())
            {
            case NodeStatus.STATUS_SUCCESS:
                m_nodeStatus = NodeStatus.STATUS_SUCCESS;
                m_preNode    = m_nodes[selectNode];
                //元に戻すため
                foreach (BaseBTNode node in m_failuerNodes)
                {
                    m_nodes.Add(node);     //m_nodesにはないはず
                }
                m_failuerNodes.Clear();
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                //ランダムに選ぶものから外すため
                m_failuerNodes.Add(m_nodes[selectNode]);
                m_nodes.RemoveAt(selectNode);
                continue;

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = NodeStatus.STATUS_RUNNING;
                //元に戻すため
                foreach (BaseBTNode node in m_failuerNodes)
                {
                    m_nodes.Add(node);     //m_nodesにはないはず
                }
                m_failuerNodes.Clear();
                return(m_nodeStatus);

            default:
                continue;
            }
        }
        //元に戻すため
        m_preNode = null;
        foreach (BaseBTNode node in m_failuerNodes)
        {
            m_nodes.Add(node); //m_nodesにはないはず
        }
        m_failuerNodes.Clear();
        m_nodeStatus = NodeStatus.STATUS_FAILURE;
        return(m_nodeStatus);
    }
예제 #11
0
 public BTRepeater(BaseBTNode node, int maxChargeTime)
 {
     m_node          = node;
     m_maxChargeTime = maxChargeTime;
     m_chargeTimer   = 0;
 }
    public override NodeStatus Evaluate()
    {
        if (m_conditionNode != null)
        {
            NodeStatus status = m_conditionNode.EvaluateCondition(m_nodeStatus);
            switch (status)
            {
            case NodeStatus.STATUS_SUCCESS:
                if (m_firstSearch)
                {
                    m_firstSearch = false;
                }
                if (m_nodes[0] != m_preNode)
                {
                    m_preNode.SetFailuer();
                }
                m_nodeStatus = m_nodes[0].Evaluate();
                m_preNode    = m_nodes[0];
                if (m_nodeStatus != NodeStatus.STATUS_RUNNING)
                {
                    m_firstSearch = true;
                }
                return(m_nodeStatus);

            case NodeStatus.STATUS_FAILURE:
                //前がToEnd実行完了のとき
                //前がNotToEnd実行中・NotToEnd実行完了のとき
                if ((m_firstSearch && m_preNode == m_nodes[0]) ||
                    (!m_firstSearch && m_preNode == m_nodes[1]))
                {
                    m_firstSearch = false;
                    if (m_nodes[1] != m_preNode)
                    {
                        m_preNode.SetFailuer();
                    }
                    m_nodeStatus = m_nodes[1].Evaluate();
                    m_preNode    = m_nodes[1];
                    return(m_nodeStatus);
                }
                else
                {
                    //前がToEnd実行中のとき
                    m_nodeStatus = m_nodes[0].Evaluate();
                    m_preNode    = m_nodes[0];
                    if (m_nodeStatus != NodeStatus.STATUS_RUNNING)
                    {
                        m_firstSearch = true;
                    }
                    return(m_nodeStatus);
                }

            case NodeStatus.STATUS_RUNNING:
                m_nodeStatus = m_preNode.Evaluate();
                if (m_nodeStatus != NodeStatus.STATUS_RUNNING &&
                    m_preNode == m_nodes[0])
                {
                    m_firstSearch = true;
                }
                return(m_nodeStatus);
            }
        }
        //ここにくるのはおかしい
        return(NodeStatus.STATUS_FAILURE);
    }
예제 #13
0
 public BTInverter(BaseBTNode node)
 {
     m_node = node;
 }
예제 #14
0
 public BTLimiter(BaseBTNode node, int maxCount)
 {
     m_node     = node;
     m_maxCount = maxCount;
     m_counter  = 0;
 }