Exemple #1
0
    // Start is called before the first frame update
    private void Start()
    {
        meshAgent  = GetComponent <NavMeshAgent>();
        testBoyFSM = new StateMachineEngine(false);

        CreateStateMachine();
    }
    public void Init()
    {
        go        = CreateGameObject("stateTest");
        behaviour = go.AddComponent <ClassWithBasicStates>();
        engine    = go.GetComponent <StateMachineEngine>();

        behaviour.Init();
    }
    /// <summary>
    /// Adds a type of <see cref="State"/> with a sub-state machine in it and its transition to the state <paramref name="stateTo"/>
    /// </summary>
    /// <param name="stateName"></param>
    /// <param name="subStateMachine">The sub-state machine inside the state</param>
    /// <param name="stateTo">The name of the state where the sub-state machine will enter</param>
    /// <returns></returns>
    public State CreateSubStateMachine(string stateName, StateMachineEngine subStateMachine, State stateTo)
    {
        State state = new State(stateName, subStateMachine.GetState("Entry_Machine"), stateTo, subStateMachine, this);

        states.Add(state.Name, state);

        return(state);
    }
Exemple #4
0
    /// <summary>
    /// Adds a type of <see cref="State"/> with a sub-state machine in it and its transition to the state <paramref name="stateTo"/>
    /// </summary>
    /// <param name="stateName"></param>
    /// <param name="subStateMachine">The sub-state machine inside the state</param>
    /// <param name="stateTo">The name of the state where the sub-state machine will enter</param>
    /// <returns></returns>
    public LeafNode CreateSubBehaviour(string nodeName, StateMachineEngine subStateMachine, State stateTo)
    {
        State    state    = new State(nodeName, subStateMachine.GetState("Entry_Machine"), stateTo, subStateMachine, this);
        LeafNode leafNode = new LeafNode("Node to return", state, this);

        subStateMachine.NodeToReturn = leafNode;
        states.Add(leafNode.StateNode.Name, leafNode.StateNode);

        return(subStateMachine.NodeToReturn);
    }
Exemple #5
0
    // Start is called before the first frame update
    private void Start()
    {
        visionCollider = GetComponentInChildren <MeshCollider>();
        meshAgent      = GetComponent <NavMeshAgent>();
        meshObstacle   = GetComponent <NavMeshObstacle>();
        animator       = GetComponent <Animator>();
        chickenFSM     = new StateMachineEngine(false);

        CreateStateMachine();
    }
Exemple #6
0
        public async Task RetrainStateMachine()
        {
            var context = new Retrain.Context();

            var engine = new StateMachineEngine <Retrain, Retrain.Context>(context);

            await engine.Start();

            // if we made it this far, it worked.
            Assert.IsTrue(true);
        }
Exemple #7
0
        public static async Task TestCFQuickStart()
        {
            var context = new CFQuickStartStateMachine.Context
            {
                ProjectName         = "dotstep-starter",
                SourceCodeDirectory = "dotstep-starter-master",
                ProjectZipLocation  = "https://github.com/paulfryer/dotstep-starter/archive/master.zip"
            };

            var engine = new StateMachineEngine <CFQuickStartStateMachine, CFQuickStartStateMachine.Context>(context);
            var sm     = new CFQuickStartStateMachine();
            await engine.Start();
        }
Exemple #8
0
    // Start is called before the first frame update
    private void Start()
    {
        behaviourTree    = new BehaviourTreeEngine(BehaviourEngine.IsNotASubmachine);
        utilityCurves    = new UtilitySystemEngine(BehaviourEngine.IsASubmachine);
        stateMachine     = new StateMachineEngine(BehaviourEngine.IsASubmachine);
        recipe           = GameObject.FindGameObjectWithTag("Recipe");
        recipeAnimator   = recipe.GetComponent <Animator>();
        handler          = transform.GetChild(5).gameObject;
        meshAgent        = GetComponent <NavMeshAgent>();
        pizzasCreated    = 0;
        pepperoniCreated = 0;

        CreateStateMachine();
        CreateUtilityCurves();
        CreateBehaviourTree();
    }
Exemple #9
0
    private void CreateStateMachine()
    {
        vehicleFSM = new StateMachineEngine(false);

        // Perceptions
        Perception radarBroken  = vehicleFSM.CreatePerception <IsInStatePerception>(radar.GetComponent <RadarFSM>().GetRadarFSM(), "Broken");
        Perception radarWorking = vehicleFSM.CreatePerception <IsInStatePerception>(radar.GetComponent <RadarFSM>().GetRadarFSM(), "Working");
        Perception direct       = vehicleFSM.CreatePerception <PushPerception>();

        // States
        State runningState  = vehicleFSM.CreateEntryState("Running", OnRunning);
        State speedUpState  = vehicleFSM.CreateState("Speed up", SpeedUp);
        State slowDownState = vehicleFSM.CreateState("Slow down", SlowDown);

        // Transitions
        vehicleFSM.CreateTransition("Radar is broken", runningState, radarBroken, speedUpState);
        vehicleFSM.CreateTransition("Radar is working", speedUpState, radarWorking, slowDownState);
        vehicleFSM.CreateTransition("To running", slowDownState, direct, runningState);
    }
Exemple #10
0
        public static async Task TestThrottledProcessor()
        {
            var lambda = new DotStep.Common.StateMachines.ThrottledProcessor.EnsureAccountAndRegionAreSet();

            var type = lambda.GetType();


            var context = new ThrottledProcessor.Context {
                StateMachineName          = "QueueToStepFunction-mIdf0XJZ3l94",
                JobQueueName              = "tiger-item",
                JobProcessingParallelSize = 10,
                MessageProcessorName      = "write-event-test",
                MessageProcessorType      = "Lambda"
            };

            var engine = new StateMachineEngine <ThrottledProcessor, ThrottledProcessor.Context>(context);

            var sm          = new ThrottledProcessor();
            var description = sm.Describe("region", "account");

            await engine.Start();
        }
Exemple #11
0
    private void CreateFiniteStateMachine()
    {
        stateMachine = new StateMachineEngine(false);

        arriveToHouse = stateMachine.CreatePerception <ArriveToDestination>(new ArriveToDestination());
        arriveToHouse.SetDestination(housePoint.position);
        ValuePerception enemyNear = stateMachine.CreatePerception <ValuePerception>(() => Vector3.Distance(transform.position, badBoy.transform.position) < 8);
        BehaviourTreeStatusPerception enterTheHouse = stateMachine.CreatePerception <BehaviourTreeStatusPerception>(behaviourTree, ReturnValues.Succeed);

        pointToRun = stateMachine.CreatePerception <ArriveToDestination>(new ArriveToDestination());

        State goToHouse        = stateMachine.CreateEntryState("Go to house", ToHouse);
        State subBehaviourTree = stateMachine.CreateSubStateMachine("Sub behaviour tree", behaviourTree);
        State runAway          = stateMachine.CreateState("Run away", RunAway);
        State enterHouse       = stateMachine.CreateState("Enter in house", EnterHouse);

        stateMachine.CreateTransition("To enter the house", goToHouse, arriveToHouse, subBehaviourTree);
        stateMachine.CreateTransition("To run away", goToHouse, enemyNear, runAway);
        behaviourTree.CreateExitTransition("Run away", subBehaviourTree, enemyNear, runAway);
        behaviourTree.CreateExitTransition("Enter the house", subBehaviourTree, enterTheHouse, enterHouse);
        stateMachine.CreateTransition("Stop running", runAway, pointToRun, goToHouse);
    }
Exemple #12
0
    private void CreateStateMachine()
    {
        radarFSM = new StateMachineEngine(false);

        // Perceptions
        Perception direct    = radarFSM.CreatePerception <PushPerception>();
        Perception breakDown = radarFSM.CreatePerception <TimerPerception>(30);
        Perception fix       = radarFSM.CreatePerception <TimerPerception>(15);

        // States
        State entryState   = radarFSM.CreateEntryState("Entry State");
        State workingState = radarFSM.CreateSubStateMachine("Working", workingSubFSM);

        brokenState = radarFSM.CreateState("Broken", Broken);

        // Transitions
        radarFSM.CreateTransition("Direct", entryState, direct, workingState);
        workingSubFSM.CreateExitTransition("To broken", workingState, breakDown, brokenState);
        radarFSM.CreateTransition("To working", brokenState, fix, workingState);

        radarFSM.Fire("Direct");
    }
Exemple #13
0
    private void CreateSubMachine()
    {
        workingSubFSM = new StateMachineEngine(true);

        // Perceptions
        detectCar = workingSubFSM.CreatePerception <DetectCar>(new DetectCar(gameObject, pointToLook));
        Perception carOverSpeed   = workingSubFSM.CreatePerception <ValuePerception>(() => detectCar.GetCarSpeed() > 20);
        Perception carOnSpeed     = workingSubFSM.CreatePerception <ValuePerception>(() => detectCar.GetCarSpeed() <= 20);
        Perception overSpeedLimit = workingSubFSM.CreateAndPerception <AndPerception>(detectCar, carOverSpeed);
        Perception onSpeedLimit   = workingSubFSM.CreateAndPerception <AndPerception>(detectCar, carOnSpeed);
        Perception timeout        = workingSubFSM.CreatePerception <TimerPerception>(2);

        // States
        State waitingForCarState = workingSubFSM.CreateEntryState("Waiting for car", OnWaitingForCar);
        State speedingState      = workingSubFSM.CreateState("Speeding", OnSpeeding);
        State correctSpeedState  = workingSubFSM.CreateState("Correct speed", OnCorrectSpeed);

        // Transitions
        workingSubFSM.CreateTransition("Car over speed limit", waitingForCarState, overSpeedLimit, speedingState);
        workingSubFSM.CreateTransition("Car on speed limit", waitingForCarState, onSpeedLimit, correctSpeedState);
        workingSubFSM.CreateTransition("To waiting for next bad car", speedingState, timeout, waitingForCarState);
        workingSubFSM.CreateTransition("To waiting for next good car", correctSpeedState, timeout, waitingForCarState);
    }
Exemple #14
0
    /// <summary>
    /// Creates a new <see cref="Transition"/> that exits from any Behaviour Engine to a State Machine. ONLY exits to State Machines
    /// </summary>
    /// <param name="transitionName">The name of the transition</param>
    /// <param name="stateFrom">The <see cref="State"/> where the transition comes from</param>
    /// <param name="perception">The <see cref="Perception"/> that will trigger the transition</param>
    /// <param name="stateTo">The <see cref="State"/> where the transition goes to. Must be a State from the super-state machine</param>
    /// <returns></returns>
    public Transition CreateExitTransition(string transitionName, State stateFrom, Perception perception, State stateTo)
    {
        if (!transitions.ContainsKey(transitionName))
        {
            StateMachineEngine superStateMachine = stateTo.BehaviourEngine as StateMachineEngine;
            Transition         exitTransition    = new Transition(transitionName, stateFrom, perception, stateTo, superStateMachine, this);

            if (stateFrom.BehaviourEngine == superStateMachine)  // Transition managed by the super-state machine
            {
                superStateMachine.transitions.Add(transitionName, exitTransition);
            }
            else   // Transition managed by the sub-state machine
            {
                transitions.Add(transitionName, exitTransition);
            }

            return(exitTransition);
        }
        else
        {
            throw new DuplicateWaitObjectException(transitionName, "The transition already exists in the behaviour engine");
        }
    }
 void Awake()
 {
     //Looks for state machine engine.
     stateMachine = GameObject.FindObjectOfType <StateMachineEngine> () as StateMachineEngine;
 }
Exemple #16
0
 /// <summary>
 /// Creates a new <see cref="Perception"/> of type <see cref="IsInStatePerception"/>
 /// </summary>
 /// <param name="stateMachineToLookIn">The State Machine where to look in</param>
 /// <param name="StateToLookFor">The name of the state to look for</param>
 /// <returns></returns>
 public IsInStatePerception CreatePerception <PerceptionType>(StateMachineEngine stateMachineToLookIn, string stateToLookFor)
 {
     return(new IsInStatePerception(stateMachineToLookIn, stateToLookFor, this));
 }
 public void Init()
 {
     go        = CreateGameObject("stateTest");
     behaviour = go.AddComponent <StateMachineBehaviour>();
     engine    = go.GetComponent <StateMachineEngine>();
 }