コード例 #1
0
    public void QueuePop()
    {
        // Create empty agent
        AI_Agent agent = AI_Agent.CreateAgent();

        // BB params
        AI_Agent.BlackBoard local = AI_Agent.BlackBoard.local;
        AI_Agent.BlackBoard global = AI_Agent.BlackBoard.global;

        string queueP1 = "TestQueue";
        string qCompare = "TestQueueComparer";

        // Create queue and populate
        fc.Queue<int> queue1 = new fc.Queue<int>();
        queue1.Add(1);
        queue1.Add(2);
        queue1.Add(3);

        // Populate the board
        agent[queueP1, local] = queue1;
        agent[qCompare, local] = -1;

        // Check size
        Assert.That(agent.NewTreeTick(T.qSize(queueP1, local, 3)) == Status.Succes);
        //errorCheck(T.qSize(queueP1, local, 3), Status.Succes, ref errors, agent);

        // Check push
        Assert.That(agent.NewTreeTick(T.qPush(queueP1, local, 4)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.qSize(queueP1, local, 4)) == Status.Succes);
        //errorCheck(T.qPush(queueP1, local, 4), Status.Succes, ref errors, agent);
        //errorCheck(T.qSize(queueP1, local, 4), Status.Succes, ref errors, agent);

        //// Check pop
        Assert.That(agent.NewTreeTick(T.qPop(queueP1, local, qCompare, local)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.qSize(queueP1, local, 3)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.eqBB(qCompare, local, 1)) == Status.Succes);
        //errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //errorCheck(T.qSize(queueP1, local, 3), Status.Succes, ref errors, agent);
        //errorCheck(T.eqBB(qCompare, local, 1), Status.Succes, ref errors, agent);

        Assert.That(agent.NewTreeTick(T.qPop(queueP1, local, qCompare, local)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.eqBB(qCompare, local, 2)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.qPop(queueP1, local, qCompare, local)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.eqBB(qCompare, local, 3)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.qPop(queueP1, local, qCompare, local)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.eqBB(qCompare, local, 4)) == Status.Succes);

        Assert.That(agent.NewTreeTick(T.qPop(queueP1, local, qCompare, local)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.qPop(queueP1, local, qCompare, local)) == Status.Succes);
        Assert.That(agent.NewTreeTick(T.eqBB(qCompare, local, 0)) == Status.Succes);

        

        //errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //errorCheck(T.eqBB(qCompare, local, 2), Status.Succes, ref errors, agent);
        //errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //errorCheck(T.eqBB(qCompare, local, 3), Status.Succes, ref errors, agent);
        //errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //errorCheck(T.eqBB(qCompare, local, 4), Status.Succes, ref errors, agent);
        //errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //errorCheck(T.qSize(queueP1, local, 0), Status.Succes, ref errors, agent);
    }
コード例 #2
0
    public void TestBTBasicCompontents(AI_Agent agent)
    {
        int errors = 0;

        #region Standard nodes

        BT_TreeNode f = T.UDel(T.failUpdate, "Fail");
        BT_TreeNode s = T.UDel(T.succesUpdate, "Succes");
        BT_TreeNode r = T.UDel(T.runningUpdate, "Running");
        BT_TreeNode b = T.UDel(T.pauseUpdate, "Pause");

        #endregion

        //if ((int)agent["Depth"] != 0)
        //    errors++;

        //SetAgentDebug(true);

        #region Composits: TC.selector, Sequencer

        // Check the TC.selector
        errorCheck(T.sel(f, f, r, s), Status.Running, ref errors, agent);
        errorCheck(T.sel(f, f, f, f), Status.Failed, ref errors, agent);
        errorCheck(T.sel(f, f, s, f), Status.Succes, ref errors, agent);

        // Check the sequencer
        errorCheck(T.seq(s, s, r, f), Status.Running, ref errors, agent);
        errorCheck(T.seq(s, s, r, s), Status.Running, ref errors, agent);
        errorCheck(T.seq(f, f, f, f), Status.Failed, ref errors, agent);
        errorCheck(T.seq(s, s, s, s), Status.Succes, ref errors, agent);

        #endregion

        #region Depth test

        // Generic depth test
        //TestDepth(agent);

        #endregion

        #region Decorators: TC.invert & alwaysFail

        // Check the TC.inverter
        errorCheck(T.inv(s), Status.Failed, ref errors, agent);
        errorCheck(T.inv(f), Status.Succes, ref errors, agent);
        errorCheck(T.inv(r), Status.Running, ref errors, agent);

        // Check the alwaysFailed
        errorCheck(T.fail(s), Status.Failed, ref errors, agent);
        errorCheck(T.fail(f), Status.Failed, ref errors, agent);
        errorCheck(T.fail(r), Status.Failed, ref errors, agent);

        #endregion

        //BT_TreeNode node = new BT_TreeNode(new BT_Decorator());

        #region Condition: CheckEqualBBParameter

        // Things to compare
        int int1 = 0;
        int int2 = 0;
        int int3 = 1;
        string str1 = "bla";
        string str2 = "bla";
        string str3 = "notbla";
        Vector3 v1 = Vector3.zero;
        Vector3 v2 = Vector3.zero;
        Vector3 v3 = Vector3.up;

        // BB params
        string p1 = "TestParam1";
        string p2 = "TestParam2";
        AI_Agent.BlackBoard local = AI_Agent.BlackBoard.local;
        AI_Agent.BlackBoard global = AI_Agent.BlackBoard.global;

        // Simple int check
        agent[p1, local] = int1;
        agent[p2, local] = int2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 0), Status.Succes, ref errors, agent);

        agent[p2, local] = int3;
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 1), Status.Failed, ref errors, agent);

        // cross global and local int check
        agent[p1, global] = int1;
        agent[p2, global] = int3;
        errorCheck(T.eqBB(p1, local, p1, global), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, p2, global), Status.Failed, ref errors, agent);

        // string check
        agent[p1, local] = str1;
        agent[p2, local] = str2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);

        agent[p2, local] = int3;
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);

        // cross global and local int check
        agent[p1, global] = str1;
        agent[p2, global] = str3;
        errorCheck(T.eqBB(p1, local, p1, global), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, p2, global), Status.Failed, ref errors, agent);

        // Vector3 check
        agent[p1, local] = v1;
        agent[p2, local] = v2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);

        agent[p2, local] = v3;
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);

        // cross global and local int check
        agent[p1, global] = v1;
        agent[p2, global] = v3;
        errorCheck(T.eqBB(p1, local, p1, global), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, p2, global), Status.Failed, ref errors, agent);


        #endregion

        #region Action: TC.copy BB value

        // int TC.copy
        // Check first
        agent[p1, local] = int1;
        agent[p2, local] = int2;

        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 0), Status.Succes, ref errors, agent);

        // now TC.copy in 3
        errorCheck(T.copy(p1, local, 3), Status.Succes, ref errors, agent);
        // Check if it went allright
        errorCheck(T.eqBB(p1, local, p2, local), Status.Failed, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 3), Status.Succes, ref errors, agent);

        // now TC.copy from p1 to p2
        errorCheck(T.copy(p2, local, p1, local), Status.Succes, ref errors, agent);

        // Check
        errorCheck(T.eqBB(p1, local, p2, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p1, local, 3), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(p2, local, 3), Status.Succes, ref errors, agent);

        #endregion

        #region Action: Queue push, pop, checkSize

        string queueP1 = "TestQueue";
        string qCompare = "TestQueueComparer";

        // Create queue and populate
        fc.Queue<int> queue1 = new fc.Queue<int>();
        queue1.Add(1);
        queue1.Add(2);
        queue1.Add(3);

        // Populate the board
        agent[queueP1, local] = queue1;
        agent[qCompare, local] = -1;

        // Check size
        errorCheck(T.qSize(queueP1, local, 3), Status.Succes, ref errors, agent);

        // Check push
        errorCheck(T.qPush(queueP1, local, 4), Status.Succes, ref errors, agent);
        errorCheck(T.qSize(queueP1, local, 4), Status.Succes, ref errors, agent);

        // Check pop
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.qSize(queueP1, local, 3), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 1), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 2), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 3), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.eqBB(qCompare, local, 4), Status.Succes, ref errors, agent);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        //Debug.Log(agent[qCompare, local]);
        errorCheck(T.qPop(queueP1, local, qCompare, local), Status.Succes, ref errors, agent);
        errorCheck(T.qSize(queueP1, local, 0), Status.Succes, ref errors, agent);

        #region Test stuff
        //Queue<int> q = new Queue<int>();
        //q.Enqueue(6);
        //q.Enqueue(4);
        //q.Enqueue(2);

        //BT_QueuePop whatev = new BT_QueuePop("test", local, "test2", local);
        ////int testooh = (int)whatev.GetFromGenericQueue(q);
        //Debug.Log((int)whatev.GetFromGenericQueue(q));
        //Debug.Log((int)whatev.GetFromGenericQueue(q));
        //Debug.Log((int)whatev.GetFromGenericQueue(q));

        //List<int> test = new List<int>() { 1, 2, 3 };
        //IList list = (IList)test;
        //Debug.Log(list[0]);


        //fc.Stack<int> stack1 = new fc.Stack<int>();
        //fc.Stack<string> stack2 = new fc.Stack<string>();
        //stack1.Add(1);
        //stack1.Add(2);
        //stack1.Add(3);

        //Debug.Log(stack1.GetType().GetGenericTypeDefinition() + " - " + stack1.Get() + " " + stack1.Get() + " " + stack1.Get() + " " + stack1.Get());
        //fc.Queue<int> queue1 = new fc.Queue<int>();
        //queue1.Add(1);
        //queue1.Add(2);
        //queue1.Add(3);

        //fc.IQueue queueI = queue1;
        //Debug.Log(queue1.GetType().GetGenericTypeDefinition() == typeof(fc.Queue<>));
        //Debug.Log(queue1.GetType().GetGenericTypeDefinition());// + " - " + queue1.Get() + " " + queue1.Get() + " " + queue1.Get() + " " + queue1.Get());
        //Debug.Log(queueI.GetType().GetGenericTypeDefinition() + " - " + queueI.Get() + " " + queueI.Get() + " " + queueI.Get() + " " + queueI.Get());
        
        #endregion

        #endregion

        //Debug.Log("Depth" + (int)agent["Depth"]);
        //if ((int)agent["Depth"] != 0)
        //    errors++;

        if (errors != 0)
            Debug.Log("Behavior Tree test FAILED - " + errors + " Errors.");
        else
            Debug.Log("Behavior Tree test SUCCES - 0 Errors.");
    }
コード例 #3
0
 public void IQueueTest()
 {
     fc.Queue<int> queue = new fc.Queue<int>();
     for (int i = 0; i < 5; i++)
     {
         queue.Add(i);
     }
     for (int i = 0; i < 5; i++)
     {
         Assert.That(((int)queue.Get()) == i);
     }
     Assert.That(((int)queue.Get()) == 0);
 }