public override BehaviourTreeStatus Tick() { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(); switch (result) { case BehaviourTreeStatus.Failure: return(BehaviourTreeStatus.Success); case BehaviourTreeStatus.Success: return(BehaviourTreeStatus.Failure); default: return(result); } /* * if (result == BehaviourTreeStatus.Failure) * { * return BehaviourTreeStatus.Success; * } * else if (result == BehaviourTreeStatus.Success) * { * return BehaviourTreeStatus.Failure; * } * else * { * return result; * }*/ }
public override void Run() { base.Run(); blackBoard.Robot = this; TurnRadarRight(360); dodgeBehaviour = new SequenceNode(blackBoard, new ScanNode(blackBoard, 360), new TrackNode(blackBoard, 360, 40), new AimNode(blackBoard), new CircleAroundNode(blackBoard)); pushBehaviour = new SequenceNode(blackBoard, new ScanNode(blackBoard, 360), new TrackNode(blackBoard, 360, 30), new TurnNode(blackBoard), new AnitGravMoveNode(blackBoard, 200), new AimNode(blackBoard), new ConditionNode(blackBoard, new Func <bool>(() => AttackCheck()), new QSNode(blackBoard))); paternBehaviour = new SequenceNode(blackBoard, new ScanNode(blackBoard, 360), new FindPattern(blackBoard), new FireNode(blackBoard, 2), new ConditionNode(blackBoard, new Func <bool>(() => blackBoard.DirectHit), new FireNode(blackBoard, 3)), new MoveNode(blackBoard, 200)); moveBehaviour = new SequenceNode(blackBoard, new ScanNode(blackBoard, 360), new TrackNode(blackBoard, 360, 40), new SetPowerNode(blackBoard), new AimNode(blackBoard), new ConditionNode(blackBoard, new Func <bool>(() => AttackCheck()), new QSNode(blackBoard)), new AnitGravMoveNode(blackBoard, 100)); antiGravBehaviour = new SequenceNode(blackBoard, new ScanNode(blackBoard, 360), new AnitGravMoveNode(blackBoard, 200), new TurnNode(blackBoard), new SetPowerNode(blackBoard), new TrackNode(blackBoard, 360, 40), new AimNode(blackBoard), new ConditionNode(blackBoard, new Func <bool>(() => AttackCheck()), new QSNode(blackBoard))); currentBehaviour = antiGravBehaviour; // divorce radar movement from gun movement IsAdjustRadarForGunTurn = true; // divorce gun movement from tank movement IsAdjustGunForRobotTurn = true; while (true) { currentBehaviour.Tick(); Execute(); } }