コード例 #1
0
        public void Transition_NodeToSubFSM_WhenPredicateIsTrue()
        {
            var n       = 0;
            var fsm     = new FSM();
            var subFSMA = new SubFSM();
            var subFSMB = new SubFSM();
            var stateA  = new StateA();
            var stateB  = new StateB();
            var stateC  = new StateC();
            var stateD  = new StateD();

            fsm.AddTransition(stateA, subFSMA, () => n == 1);
            subFSMA.AddTransition(stateB, subFSMB, () => n == 2);
            subFSMB.AddTransition(stateC, stateD, () => n == 3);

            fsm.Start();
            n = 1;
            fsm.Update();
            n = 2;
            fsm.Update();
            n = 3;
            fsm.Update();

            Assert.IsTrue(fsm.CurrentNode == subFSMA && subFSMA.CurrentNode == subFSMB && subFSMB.CurrentNode == stateD);
        }
コード例 #2
0
        public void RemoveNode_FromFSM()
        {
            var fsm    = new FSM();
            var stateA = new StateA();
            var stateB = new StateB();
            var stateC = new StateC();

            fsm.AddTransition(stateA, stateB, () => true);
            fsm.AddTransition(stateB, stateC, () => true);

            fsm.RemoveNode(stateB);

            Assert.IsTrue(!fsm.Contains(stateB));
        }
コード例 #3
0
        public void RemoveSubFSM_FromFSM()
        {
            var fsm    = new FSM();
            var subFSM = new SubFSM();
            var stateA = new StateA();
            var stateB = new StateB();
            var stateC = new StateC();
            var stateD = new StateD();

            subFSM.AddTransition(stateC, stateD, () => true);
            fsm.AddTransition(stateA, stateB, () => true);
            fsm.AddTransition(stateB, subFSM, () => true);
            fsm.RemoveNode(subFSM);

            Assert.IsTrue(!fsm.Contains(subFSM) && !fsm.Contains(stateC) && !fsm.Contains(stateD));
        }
コード例 #4
0
        public void Transition_FromAnyNode_WhenPredicateIsTrue()
        {
            var n      = 0;
            var fsm    = new FSM();
            var stateA = new StateA();
            var stateB = new StateB();
            var stateC = new StateC();

            fsm.AddTransition(stateA, stateB, () => n == 1);
            fsm.AddTransitionFromAnyNode(stateC, () => n == 2);

            fsm.Start();
            n = 1;
            fsm.Update();
            n = 2;
            fsm.Update();

            Assert.IsTrue(fsm.CurrentNode == stateC);
        }
コード例 #5
0
        public void Transition_NodeToSubFSM_WhenPredicateIsTrue()
        {
            var n      = 0;
            var fsm    = new FSM();
            var subFSM = new SubFSM();
            var stateA = new StateA();
            var stateB = new StateB();
            var stateC = new StateC();

            subFSM.AddTransition(stateB, stateC, () => n == 2);
            fsm.AddTransition(stateA, subFSM, () => n == 1);

            fsm.Start();
            n = 1;
            fsm.Update();
            n = 2;
            fsm.Update();

            Assert.IsTrue(fsm.CurrentNode == subFSM && subFSM.CurrentNode == stateC);
        }