public void can_create_selector() { Init(); var invokeCount = 0; var parallel = testObject .Selector("some-selector") .Do("some-action-1", t => { ++invokeCount; return(MyBehaviourTreeStatus.Failure); }) .Do("some-action-2", t => { ++invokeCount; return(MyBehaviourTreeStatus.Success); }) .End() .Build(); Assert.IsType <SelectorNode>(parallel); Assert.Equal(MyBehaviourTreeStatus.Success, parallel.Tick(new MyTimeData())); Assert.Equal(2, invokeCount); }
/// <summary> /// Parsers the specified input. /// </summary> /// <param name="input">The input.</param> public void parser(byte[] input) { //this is a parser that creates the tree by reading the //byte array that is passed in as aperamiter var builder = new MyTreeBuilder(crouched, close, medium, far); IMyBehaviourTreeNode botTree; for (int i = 0; i < input.Length; i++) { switch (input[i]) { case Root_Node: builder.Sequence("Root-Sequence-Node"); break; case Punch: builder.Punch(gw, AI, NAI); break; case Kick: builder.Kick(gw, AI, NAI); break; case Special: builder.Special(gw, AI, NAI); break; case isCrouched: builder.Condition ("is_Opponent_Crouched", t => { if (builder.Crouched == true) { return(true); } return(false); }); builder.Selector("If_Crouched"); break; case isClose: builder.Condition ("is_Opponent_Close", t => { if (builder.Close == true) { return(true); } return(false); }); builder.Selector("If_Close"); break; case isMedium: builder.Condition ("is_Opponent_Medium", t => { if (builder.Medium == true) { return(true); } return(false); }); builder.Selector("If_Medium"); break; case isFar: builder.Condition ("is_Opponent_Far", t => { if (builder.Far == true) { return(true); } return(false); }); builder.Selector("If_Far"); break; case End: builder.End().Build(); break; } } //will have gotten nodes from parser so should build botTree = builder.Build(); interp_tree_builder = builder; interp_tree = botTree; }