當前位置: 首頁>>代碼示例>>C#>>正文


C# Agent.getAgentNumber方法代碼示例

本文整理匯總了C#中Agent.getAgentNumber方法的典型用法代碼示例。如果您正苦於以下問題:C# Agent.getAgentNumber方法的具體用法?C# Agent.getAgentNumber怎麽用?C# Agent.getAgentNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Agent的用法示例。


在下文中一共展示了Agent.getAgentNumber方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetActionForAgent

    //Traverse the leafs of the tree to find a suitable task for this agent
    public string GetActionForAgent(Agent agent)
    {
        //Check if the agent already has a node as its own
        foreach(TreeNode leaf in leafs)
        {
            if(leaf.GetOwner() != null && leaf.GetOwner().getAgentNumber() == agent.getAgentNumber()) //if agent already owns a node
            {
                return leaf.GetActionName();
            }
            else if(leaf.GetOwner() != null) { //if an agent already is assisting on a node

                if(OkayToAssist(agent, leaf, 2))
                {
                    //Debug.Log("AGNETSTHATDOACVTION " + agents[0] + " " + agents[1] + " for action " + leaf.GetActionName());
                    return "AssistingAction";
                }
            }
        }

        foreach(TreeNode leaf in leafs)
        {
            List<string> agents = ActionManager.Instance.AssistingAgentsToAction(agent.getAgentType(), leaf.GetActionName());

            if(agents.Count > 0 && leaf.GetOwnerNumber() == System.Guid.Empty )
            {
                leaf.SetOwner(agent);
                return leaf.GetActionName();
            }
            else if(agents.Count > 1 && leaf.GetOwnerNumber() != System.Guid.Empty && agent.getAgentType() != leaf.GetOwner().getAgentType())
            {

                if(OkayToAssist(agent, leaf, 1))
                {
                    leaf.GetAssisters().Add(agent);
                    //Debug.Log("AGNETSTHATDOACVTION " + agents[0] + " " + agents[1] + " for action " + leaf.GetActionName());
                    return "AssistingAction";
                }
            }
        }

        return "IdleAction"; //empty string means no match, agent cant to any of the leaf-node-actions
    }
開發者ID:RikardGehlin,項目名稱:Exjobb,代碼行數:43,代碼來源:TaskTree.cs

示例2: RemoveAgentFromOwnedNode

    public void RemoveAgentFromOwnedNode(Agent agent)
    {
        TreeNode ownedNode = GetOwnedNode(agent.getAgentNumber());
        if(ownedNode.GetPosition() != new Vector3(30, 0.5f, 30))
        {
            if(ownedNode.GetOwner().getAgentNumber() == agent.getAgentNumber())
            {
                ownedNode.SetOwner(null);
            } else {

                ownedNode.GetAssisters().Remove(agent);
            }
        }
    }
開發者ID:RikardGehlin,項目名稱:Exjobb,代碼行數:14,代碼來源:TaskTree.cs

示例3: RemoveNode

    //Removes a node in the leafs that this agent owns and adds its parent
    public void RemoveNode(Agent agent)
    {
        TreeNode ownedNode = GetOwnedNode(agent.getAgentNumber());
        List<Agent> assisters = ownedNode.GetAssisters();
        leafs.Remove(ownedNode);

        int level = -1;
        foreach(List<TreeNode> list in tree)
        {
            level++;
            if(list.Contains(ownedNode))
            {
                list.Remove(ownedNode);
                break;
            }
        }

        //Debug.Log (agent.getAgentType());
        //Debug.Log(ownedNode.GetParent().GetActionName());
        if(ownedNode.GetParent() != null)
        {
            List<string> agents = ActionManager.Instance.AssistingAgentsToAction(agent.getAgentType(), ownedNode.GetParent().GetActionName());
            assisters = ownedNode.GetParent().GetAssisters();

            if(HasChild(tree[level], ownedNode.GetParent()) == false )
            {

                int nrAgentToDoAction = agents.FindAll(item => item == agent.getAgentType()).Count;
                int nrSameColorAssisters = 0;

                foreach(Agent assister in assisters)
                {
                    if(assister.getAgentType() == agent.getAgentType())
                    {
                        nrSameColorAssisters++;
                    }
                }

                leafs.Add(ownedNode.GetParent());

                if(nrAgentToDoAction - nrSameColorAssisters == 1)
                {

                    ownedNode.GetParent().SetOwner(agent);

                } else {

                    foreach(Agent assister in assisters)
                    {
                        if(assister.getAgentType() == agent.getAgentType())
                        {
                            ownedNode.GetParent().SetOwner(assister);
                            assisters.Remove(assister);
                            break;
                        }
                    }
                }

                //PrintLeafs();

            } else if (HasChild(tree[level], ownedNode.GetParent()) == true)
            {
                if(agents.Contains(agent.getAgentType()))
                {
                    if(OkayToAssist(agent,  ownedNode.GetParent(), 1))
                    {
                        ownedNode.GetParent().GetAssisters().Add(agent);
                    }
                }
            }
        }

        Debug.Log ("!!!!!!!!!!!Remove node!!!!!!!!!!!!!");

        //PrintTree();
    }
開發者ID:RikardGehlin,項目名稱:Exjobb,代碼行數:77,代碼來源:TaskTree.cs

示例4: OkayToAssist

    public bool OkayToAssist(Agent agent, TreeNode ownedNode, int mode)
    {
        bool okToAssist;

        if(mode == 1)
        {
            okToAssist = true;
        } else {

            okToAssist = false;
        }

        List <Agent> assisters = ownedNode.GetAssisters();

            foreach(Agent assister in assisters)
            {
                if(mode == 1 && assister.getAgentType() == agent.getAgentType())
                {
                    okToAssist = false;
                } else if(mode == 2 && assister.getAgentNumber() == agent.getAgentNumber())
                {
                    okToAssist = true;
                }
            }

        return okToAssist;
    }
開發者ID:RikardGehlin,項目名稱:Exjobb,代碼行數:27,代碼來源:TaskTree.cs


注:本文中的Agent.getAgentNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。