Example #1
0
        public static void Run()
        {
            var model   = new StateMachine <Instance>("compTest");
            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);

            var activity1 = new State <Instance>("activity1", model);
            var activity2 = new State <Instance>("activity2", model);
            var activity3 = new State <Instance>("activity3", model);
            var junction1 = new PseudoState <Instance>("junction1", model, PseudoStateKind.Junction);
            var junction2 = new PseudoState <Instance>("junction2", model, PseudoStateKind.Junction);
            var end       = new FinalState <Instance>("end", model);

            var subInitial = new PseudoState <Instance>("subInitial", activity2, PseudoStateKind.Initial);
            var subEnd     = new FinalState <Instance>("subEnd", activity2);

            subInitial.To(subEnd);
            initial.To(activity1);
            activity1.To(activity2);
            activity2.To(junction1);
            junction1.To(junction2).Else();
            junction2.To(activity3).Else();
            activity3.To(end);

            model.Validate();

            var instance = new Instance("transitions");

            model.Initialise(instance);

            Trace.Assert(model.IsComplete(instance));
        }
Example #2
0
		public static void Test()
		{
			var machine = new Region( "history" );

			var initial = new PseudoState( "initial", PseudoStateKind.Initial, machine );
			var shallow = new CompositeState( "shallow", machine );
			var deep = new SimpleState( "deep", machine );
			var final = new FinalState( "final", machine );

			var s1 = new SimpleState( "s1", shallow );
			var s2 = new SimpleState( "s2", shallow );

			new Transition( initial, shallow );
			new Transition( new PseudoState( "shallow", PseudoStateKind.ShallowHistory, shallow ), s1 );
			new Transition<String>( s1, s2, c => c.Equals( "move" ) );
			new Transition<String>( shallow, deep, c => c.Equals( "go deep" ) );
			new Transition<String>( deep, shallow, c => c.Equals( "go shallow" ) );
			new Transition<String>( s2, final, c => c.Equals( "end" ) );

			var state = new State();

			machine.Initialise( state );

			Trace.Assert( machine.Process( state, "move" ) );
			Trace.Assert( machine.Process( state, "go deep" ) );
			Trace.Assert( machine.Process( state, "go shallow" ) );
			Trace.Assert( !machine.Process( state, "go shallow" ) );
			Trace.Assert( machine.Process( state, "end" ) );
			Trace.Assert( machine.IsComplete( state ) );
		}
Example #3
0
		public static void Run () {
			var model = new StateMachine<Instance>("compTest");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);

			var activity1 = new State<Instance>("activity1", model);
			var activity2 = new State<Instance>("activity2", model);
			var activity3 = new State<Instance>("activity3", model);
			var junction1 = new PseudoState<Instance>("junction1", model, PseudoStateKind.Junction);
			var junction2 = new PseudoState<Instance>("junction2", model, PseudoStateKind.Junction);
			var end = new FinalState<Instance>("end", model);

			var subInitial = new PseudoState<Instance>("subInitial", activity2, PseudoStateKind.Initial);
			var subEnd = new FinalState<Instance>("subEnd", activity2);

			subInitial.To(subEnd);
			initial.To(activity1);
			activity1.To(activity2);
			activity2.To(junction1);
			junction1.To(junction2).Else();
			junction2.To(activity3).Else();
			activity3.To(end);

			model.Validate();

			var instance = new Instance("transitions");
			model.Initialise(instance);

			Trace.Assert(model.IsComplete(instance));
		}
        public void Stop(FinalState finalState = FinalState.RemainCurrent)
        {
            IsPlaying = false;

            switch (finalState)
            {
            case FinalState.RemainCurrent:
                // Nothing to do.
                break;

            case FinalState.SameAsBegin:
                BeginTime = CurrentTime - Duration;
                break;

            case FinalState.SameAsEnd:
                BeginTime = CurrentTime;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(finalState), finalState, null);
            }
            UpdateImpl();

            StopImpl();

            Stopped?.Invoke();
        }
Example #5
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");

			var initial = new PseudoState<Instance>("initial", model);

			var choice = new PseudoState<Instance>("choice", model, PseudoStateKind.Choice);
			var junction = new PseudoState<Instance>("junction", model, PseudoStateKind.Junction);

			var finalState = new FinalState<Instance>("final", model);

			initial.To(choice);
			choice.To(junction).When(i => i.Int1 == 0).Effect(i => i.Int1 = 1);
			choice.To(finalState).Else();
			junction.To(choice).When(i => i.Int2 == 0).Effect(i => i.Int2 = 2);

			model.Validate();

			var instance = new Instance("else");

			model.Initialise(instance);

			Trace.Assert(model.IsComplete(instance));
			Trace.Assert(instance.Int1 == 1);
			Trace.Assert(instance.Int2 == 2);
		}
Example #6
0
        override public void VisitFinalState(FinalState <TInstance> finalState)
        {
            base.VisitFinalState(finalState);

            // [1] A final state cannot have any outgoing transitions.
            if (finalState.Outgoing.Count != 0)
            {
                Console.Error.WriteLine(finalState + ": final states must not have outgoing transitions.");
            }

            // [2] A final state cannot have regions.
            if (finalState.Regions.Count != 0)
            {
                Console.Error.WriteLine(finalState + ": final states must not have child regions.");
            }

            // [4] A final state has no entry behavior.
            if (finalState.entryBehavior != null)
            {
                Console.Error.WriteLine(finalState + ": final states may not have entry behavior.");
            }

            // [5] A final state has no exit behavior.
            if (finalState.exitBehavior != null)
            {
                Console.Error.WriteLine(finalState + ": final states may not have exit behavior.");
            }
        }
Example #7
0
		public static void Run () {
			var model = new StateMachine<Instance>("history");

			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var shallow = new State<Instance>("shallow", model);
			var deep = new State<Instance>("deep", model);
			var end = new FinalState<Instance>("final", model);

			var s1 = new State<Instance>("s1", shallow);
			var s2 = new State<Instance>("s2", shallow);

			initial.To(shallow);
			new PseudoState<Instance>("shallow", shallow, PseudoStateKind.ShallowHistory).To(s1);
			s1.To(s2).When<string>(c => c == "move");
			shallow.To(deep).When<string>(c => c == "go deep");
			deep.To(shallow).When<string>(c => c == "go shallow");
			s2.To(end).When<string>(c => c == "end");

			model.Validate();

			var instance = new Instance("history");

			model.Initialise(instance);

			model.Evaluate(instance, "move");
			model.Evaluate(instance, "go deep");
			model.Evaluate(instance, "go shallow");
			model.Evaluate(instance, "end");

			Trace.Assert(model.IsComplete(instance));
		}
Example #8
0
        public static void Run()
        {
            var model = new StateMachine <Instance>("model");

            var initial = new PseudoState <Instance>("initial", model);

            var choice   = new PseudoState <Instance>("choice", model, PseudoStateKind.Choice);
            var junction = new PseudoState <Instance>("junction", model, PseudoStateKind.Junction);

            var finalState = new FinalState <Instance>("final", model);

            initial.To(choice);
            choice.To(junction).When(i => i.Int1 == 0).Effect(i => i.Int1 = 1);
            choice.To(finalState).Else();
            junction.To(choice).When(i => i.Int2 == 0).Effect(i => i.Int2 = 2);

            model.Validate();

            var instance = new Instance("else");

            model.Initialise(instance);

            Trace.Assert(model.IsComplete(instance));
            Trace.Assert(instance.Int1 == 1);
            Trace.Assert(instance.Int2 == 2);
        }
Example #9
0
        public static void Run()
        {
            var model = new StateMachine <Instance>("history");

            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var shallow = new State <Instance>("shallow", model);
            var deep    = new State <Instance>("deep", model);
            var end     = new FinalState <Instance>("final", model);

            var s1 = new State <Instance>("s1", shallow);
            var s2 = new State <Instance>("s2", shallow);

            initial.To(shallow);
            new PseudoState <Instance>("shallow", shallow, PseudoStateKind.ShallowHistory).To(s1);
            s1.To(s2).When <string>(c => c == "move");
            shallow.To(deep).When <string>(c => c == "go deep");
            deep.To(shallow).When <string>(c => c == "go shallow");
            s2.To(end).When <string>(c => c == "end");

            model.Validate();

            var instance = new Instance("history");

            model.Initialise(instance);

            model.Evaluate(instance, "move");
            model.Evaluate(instance, "go deep");
            model.Evaluate(instance, "go shallow");
            model.Evaluate(instance, "end");

            Trace.Assert(model.IsComplete(instance));
        }
Example #10
0
        public void Change(IReturnAlgorithm returnAlgorithm, IRobotCleaner robot)
        {
            var position = new FinalState(robot.X, robot.Y, robot.FaceTo);
            var response = new ResponseDto(robot.Map.Visited, robot.Map.Cleaned, position, robot.Battery);

            throw new OutOfMovesException("Robot ran out of moves", JsonConvert.SerializeObject(response));
        }
        public void Transitions()
        {
            var f = new StateMachine()
            {
                Ref = "Ref0"
            };

            f.States.Add(new StartState()
            {
                Ref = "Ref1", Name = "Start", NextState = "State1"
            });

            var st = new State()
            {
                Ref = "Ref2", Name = "State1", NextState = "Final"
            };
            var t1 = new Transition()
            {
                Condition = "Arg.t > Arg.x", Action = new Assign()
                {
                    Ref = "Ref7", To = "Arg.t", Value = "Arg.t - 1"
                },
                Destination = "State1"
            };

            st.Transitions.Add(t1);
            f.States.Add(st);

            var fs = new FinalState()
            {
                Ref = "Ref3", Name = "Final"
            };

            fs.Entry = new Assign()
            {
                Ref = "Ref4", To = "Result.res", Value = "Arg.t"
            };
            f.States.Add(fs);

            var wf = new Workflow()
            {
                Root = f
            };

            var objCode = wf.Compile();

            var arg = new DynamicObject();

            arg.Set("x", 5);
            arg.Set("t", 12);
            objCode.Run(arg);
            var res = objCode.Result;

            Assert.AreEqual(5, res.Eval <Int32>("res"));
        }
Example #12
0
        private void ValidateMove(int cost)
        {
            var batteryState = Battery - cost;

            if (batteryState < 0)
            {
                var finalState = new FinalState(X, Y, FaceTo);
                var response   = new ResponseDto(Map.Visited, Map.Cleaned, finalState, Battery);
                throw new OutOfBatteryException("Battery died", JsonConvert.SerializeObject(response));
            }
        }
Example #13
0
 /// <summary>
 /// Application report constructor
 /// </summary>
 internal ApplicationReport(string appId, string appName, string trackingUrl,
                            long startedTime, long finishedTime, int numberOfRunningEvaluators, FinalState finalState)
 {
     AppId        = appId;
     AppName      = appName;
     TrackingUrl  = trackingUrl == null ? null : new Uri(trackingUrl);
     FinalState   = finalState;
     StartedTime  = startedTime;
     FinishedTime = finishedTime;
     NumberOfRunningEvaluators = numberOfRunningEvaluators;
 }
        /// <summary>
        /// Calls the respective command based on the parameter given in the constructor.
        /// When it's done, an final status will be returned as result of the operation.
        /// </summary>
        /// <param name="robot"></param>
        /// <returns></returns>
        public ResponseDto Clean(IRobotCleaner robot)
        {
            foreach (var command in _commands)
            {
                _com[command].Execute(robot);
            }

            var position = new FinalState(robot.X, robot.Y, robot.FaceTo);
            var response = new ResponseDto(robot.Map.Visited, robot.Map.Cleaned, position, robot.Battery);

            return(response);
        }
Example #15
0
        /// <summary>
        /// Initial/Final State도 복제하여 레퍼런스가 아닌 자기 자신만의 상태로 만든다.
        /// </summary>
        public void MakeItHardClone()
        {
            InitialState              = InitialState.Clone();
            InitialState.ClonedFrom   = null;
            InitialState.InitialState = null;
            InitialState.FinalState   = null;

            FinalState              = FinalState.Clone();
            FinalState.ClonedFrom   = null;
            FinalState.InitialState = null;
            FinalState.InitialState = null;
        }
Example #16
0
		public static void Test()
		{
			try
			{
				var main = new Region<State>( "muximise1" );

				var initial = new PseudoState<State>( "initial", PseudoStateKind.Initial, main );
				var ortho = new OrthogonalState<State>( "ortho", main );
				var simple = new SimpleState<State>( "simple", main );
				var final = new FinalState<State>( "final", main );

				var r1 = new Region<State>( "r1", ortho );
				var r2 = new Region<State>( "r2", ortho );

				var i1 = new PseudoState<State>( "initial", PseudoStateKind.ShallowHistory, r1 );
				var i2 = new PseudoState<State>( "initial", PseudoStateKind.ShallowHistory, r2 );

				var s1 = new SimpleState<State>( "s1", r1 );
				var s2 = new SimpleState<State>( "s2", r2 );

				var f1 = new FinalState<State>( "f1", r1 );
				var f2 = new FinalState<State>( "f2", r2 );

				new Transition<State>( initial, ortho );

				new Transition<State>( i1, s1 );
				new Transition<State>( i2, s2 );

				new Transition<State>( ortho, final ); // This should happen once all regions in ortho are complete?

				new Transition<State, String>( s1, f1, ( s, c ) => c == "complete1" );
				new Transition<State, String>( s2, f2, ( s, c ) => c == "complete2" );

				new Transition<State, String>( ortho, simple, ( s, c ) => c == "jump" );
				new Transition<State, String>( simple, ortho, ( s, c ) => c == "back" );

				var state = new State();

				main.Initialise( state );

				main.Process( state, "complete1" );
				main.Process( state, "complete2" );

				Trace.Assert( main.IsComplete( state ) );

			}
			catch( Exception x )
			{
				Trace.Fail( x.Message );
			}
		}
Example #17
0
        private void SetQuestionsStates()
        {
            question1State = new Question1State(this, _sequenceMachine, question1UIScreen);
            question2State = new Question2State(this, _sequenceMachine, question2UIScreen);
            question3State = new Question3State(this, _sequenceMachine, question3UIScreen);
            question4State = new Question4State(this, _sequenceMachine, question4UIScreen);
            question5State = new Question5State(this, _sequenceMachine, question5UIScreen);
            question6State = new Question6State(this, _sequenceMachine, question6UIScreen);
            question7State = new Question7State(this, _sequenceMachine, question7UIScreen);
            question8State = new Question8State(this, _sequenceMachine, question8UIScreen);
            question9State = new Question9State(this, _sequenceMachine, question9UIScreen);

            finalState = new FinalState(this, _sequenceMachine, finalSequenceUIScreen);
        }
Example #18
0
        public bool UpdateStatus(Guid congressId, List <Guid> guids, FinalState status)
        {
            ModelView.InFormEntitiyList <Article> articles = new ModelView.InFormEntitiyList <Article>();
            bool      result;
            ArticleBO articleBo = new ArticleBO();

            try
            {
                ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
                if (!guids.Any())
                {
                    return(true);
                }

                List <Article> list = articleBo.Where(ConnectionHandler, x => x.Id.In(guids));
                foreach (Article item in list)
                {
                    item.FinalState = (byte)status;
                    articleBo.AdminSetStatus(item);
                    articleBo.Update(ConnectionHandler, item);
                    articles.Add(item, Resources.Congress.ArticleChangeStatusEmail, Resources.Congress.ArticleChangeStatusSMS);
                }
                ConnectionHandler.CommitTransaction();
                result = true;
            }
            catch (KnownException ex)
            {
                ConnectionHandler.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            catch (Exception ex)
            {
                ConnectionHandler.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            try
            {
                if (result)
                {
                    articleBo.InformArticle(ConnectionHandler, congressId, articles);
                }
            }
            catch (Exception)
            {
            }
            return(result);
        }
Example #19
0
    void UpdateState()
    {
        switch (currentState)
        {
        case (FinalState.SPLASH_1):
            if (currentTime >= SPLASH_1_TIME)
            {
                Music.Play();
                splash1.SetActive(false);
                splash2.SetActive(true);
                currentState = FinalState.SPLASH_2;
                currentTime  = 0;
            }
            break;

        case (FinalState.SPLASH_2):
            if (currentTime >= SPLASH_2_TIME)
            {
                splash2.SetActive(false);
                splash3.SetActive(true);
                currentState = FinalState.SPLASH_3;
                currentTime  = 0;
            }
            break;

        case (FinalState.SPLASH_3):
            if (currentTime >= SPLASH_3_TIME)
            {
                splash3.SetActive(false);
                final.SetActive(true);
                currentState = FinalState.PRE_EXIT;
                currentTime  = 0;
            }
            break;

        case (FinalState.PRE_EXIT):
            if (currentTime >= PRE_EXIT_TIME)
            {
                exitButton.SetActive(true);
                currentState = FinalState.PRE_EXIT;
                currentTime  = 0;
            }
            break;

        default:
            break;
        }
    }
        public void Build_Basic_Graph( )
        {
            FlowDiagramControl flowDiagram = new FlowDiagramControl( );

            var initialState = new InitialState( );
            var dp           = new DecisionPoint( );
            var finalState   = new FinalState( );

            flowDiagram.AddShape(initialState);
            flowDiagram.AddShape(dp);
            flowDiagram.AddShape(finalState);

            initialState.Connection.To = dp;
            dp.True.To  = finalState;
            dp.False.To = finalState;
        }
        public void FinalEntry()
        {
            var f = new StateMachine()
            {
                Ref = "Ref0"
            };

            f.States.Add(new StartState()
            {
                Ref = "Ref1", Name = "Start", NextState = "State1"
            });

            var st = new State()
            {
                Ref = "Ref2", Name = "State1", NextState = "Final"
            };

            f.States.Add(st);

            var fs = new FinalState()
            {
                Ref = "Ref3", Name = "Final"
            };

            fs.Entry = new Assign()
            {
                Ref = "Ref4", To = "Result.res", Value = "5"
            };
            f.States.Add(fs);

            var wf = new Workflow()
            {
                Root = f
            };

            var objCode = wf.Compile();

            var arg = new DynamicObject();

            arg.Set("x", 5);
            arg.Set("t", 10);
            objCode.Run(arg);
            var res = objCode.Result;

            Assert.AreEqual(5, res.Eval <Int32>("res"));
        }
        //    [Test]
        public void Convert_From_Graph_To_StateMap( )
        {
            FlowDiagramControl flowDiagram = new FlowDiagramControl();

            var initialState = new InitialState();
            var dp           = new DecisionPoint();
            var finalState   = new FinalState();

            flowDiagram.AddShape(initialState);
            flowDiagram.AddShape(dp);
            flowDiagram.AddShape(finalState);

            initialState.Connection.To = dp;
            dp.True.To  = finalState;
            dp.False.To = finalState;

            flowDiagram.Convert(false);
        }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!isPause)
            {
                PauseMenu.SetActive(true);
                isPause        = true;
                Time.timeScale = 0;
            }
            else if (isPause)
            {
                PauseMenu.SetActive(false);
                isPause        = false;
                Time.timeScale = 1;
            }
        }

        AllyPortHP  = AllyPort.GetComponent <PortHealth> ().health;
        EnemyPortHP = EnemyPort.GetComponent <PortHealth> ().health;
        Scene scene = SceneManager.GetActiveScene();

        if (scene.name != "Pengujian")        // name of scene
        {
            if (AllyPortHP <= 0)
            {
                GameOver.SetActive(true);
                FinalState.GetComponent <Text> ().text = "Kalah!\nMarkasmu sudah dihancurkan musuh";
                Time.timeScale = 0;
            }
            else if (EnemyPortHP <= 0)
            {
                GameOver.SetActive(true);
                FinalState.GetComponent <Text> ().text = "Menang!\nMarkas musuh berhasil dihancurkan";
                Time.timeScale = 0;
            }
        }
        SteelText.text = System.Convert.ToString(GetRes.SteelRes);
        FuelText.text  = System.Convert.ToString(GetRes.FuelRes);
    }
Example #24
0
		public static void Run () {
			var model = new StateMachine<Instance>("model");

			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var ortho = new State<Instance>("ortho", model);
			var simple = new State<Instance>("simple", model);
			var final = new FinalState<Instance>("final", model);

			var r1 = new Region<Instance>("r1", ortho);
			var r2 = new Region<Instance>("r2", ortho);

			var i1 = new PseudoState<Instance>("initial", r1, PseudoStateKind.ShallowHistory);
			var i2 = new PseudoState<Instance>("initial", r2, PseudoStateKind.ShallowHistory);

			var s1 = new State<Instance>("s1", r1);
			var s2 = new State<Instance>("s2", r2);

			var f1 = new FinalState<Instance>("f1", r1);
			var f2 = new FinalState<Instance>("f2", r2);

			initial.To(ortho);

			i1.To(s1);
			i2.To(s2);

			ortho.To(final); // This should happen once all regions in ortho are complete?

			s1.To(f1).When<string>(c => c == "complete1");
			s2.To(f2).When<string>(c => c == "complete2");

			ortho.To(simple).When<string>(c => c == "jump");
			simple.To(ortho).When<string>(c => c == "back");

			model.Validate();

			var instance = new Instance("muximise");
			model.Initialise(instance);
			/*
console.log("simple.isSimple = " + simple.isSimple());
console.log("simple.isComposite = " + simple.isComposite());
console.log("simple.isOrthogonal = " + simple.isOrthogonal());

console.log("model.isSimple = " + model.isSimple());
console.log("model.isComposite = " + model.isComposite());
console.log("model.isOrthogonal = " + model.isOrthogonal());

console.log("ortho.isSimple = " + ortho.isSimple());
console.log("ortho.isComposite = " + ortho.isComposite());
console.log("ortho.isOrthogonal = " + ortho.isOrthogonal());
*/

			Trace.Assert(simple.IsSimple);
			Trace.Assert(!model.IsSimple);
			Trace.Assert(!ortho.IsSimple);

			Trace.Assert(!simple.IsComposite);
			Trace.Assert(model.IsComposite);
			Trace.Assert(ortho.IsComposite);

			Trace.Assert(!simple.IsOrthogonal);
			Trace.Assert(!model.IsOrthogonal);
			Trace.Assert(ortho.IsOrthogonal);

			model.Evaluate(instance, "complete1");
			model.Evaluate(instance, "complete2");

			Trace.Assert(model.IsComplete(instance));
		}
Example #25
0
 public void flingAndExplode()
 {
     setFinalState = FinalState.EXPLODE;
     move();
 }
Example #26
0
 /// <summary>
 /// Visits a final state within a state machine model.
 /// </summary>
 /// <param name="finalState">The final state to visit.</param>
 /// <remarks>Prior to visiting the final state, it is visited as the state type.</remarks>
 public virtual void VisitFinalState(FinalState <TInstance> finalState)
 {
     this.VisitState(finalState);
 }
Example #27
0
 public void fling()
 {
     setFinalState = FinalState.NOTHING;
     move();
 }
Example #28
0
 public void flingAndHurt()
 {
     setFinalState = FinalState.HURT;
     move();
 }
Example #29
0
 public void flingAndExplode()
 {
     setFinalState = FinalState.EXPLODE;
     move();
 }
Example #30
0
 public void fling()
 {
     setFinalState = FinalState.NOTHING;
     move();
 }
        public void SaveRestore()
        {
            var f = new StateMachine()
            {
                Ref = "Ref0"
            };

            f.States.Add(new StartState()
            {
                Ref = "Ref1", Name = "Start", NextState = "State1"
            });

            var st = new State()
            {
                Ref = "Ref2", Name = "State1", NextState = "Final"
            };

            st.Entry = new Bookmark()
            {
                Ref = "Ref21", Name = "Bookmark"
            };
            st.Exit = new Assign()
            {
                Ref = "Ref22", To = "Arg.x", Value = "Arg.x + Arg.x"
            };
            f.States.Add(st);

            var fs = new FinalState()
            {
                Ref = "Ref3", Name = "Final"
            };

            fs.Entry = new Assign()
            {
                Ref = "Ref4", To = "Result.res", Value = "Arg.x"
            };
            f.States.Add(fs);

            var wf = new Workflow()
            {
                Root = f
            };

            var objCode = wf.Compile();

            var arg = new DynamicObject();

            arg.Set("x", 5);

            var state = objCode.Run(arg);

            Assert.AreEqual(CodeState.Wait, state);

            var res = objCode.Result;

            Assert.AreEqual(0, res.Eval <Int32>("res"));


            var stored = objCode.Store();
            var wf2    = new Workflow()
            {
                Root = f
            };
            var objCode2 = wf.Compile();

            objCode2.Restore(stored);

            objCode2.Resume("Bookmark", new DynamicObject());
            res = objCode2.Result;
            Assert.AreEqual(10, res.Eval <Int32>("res"));
        }
Example #32
0
 public RefuilingState(Tutorial context, ChainedState _back)
     : base(context)
 {
     back = _back;
     next = new FinalState(context);
 }
Example #33
0
 public void flingAndHurt()
 {
     setFinalState  = FinalState.HURT;
     move();
 }
Example #34
0
        public static void Run()
        {
            var model = new StateMachine <Instance>("model");

            var initial = new PseudoState <Instance>("initial", model, PseudoStateKind.Initial);
            var ortho   = new State <Instance>("ortho", model);
            var simple  = new State <Instance>("simple", model);
            var final   = new FinalState <Instance>("final", model);

            var r1 = new Region <Instance>("r1", ortho);
            var r2 = new Region <Instance>("r2", ortho);

            var i1 = new PseudoState <Instance>("initial", r1, PseudoStateKind.ShallowHistory);
            var i2 = new PseudoState <Instance>("initial", r2, PseudoStateKind.ShallowHistory);

            var s1 = new State <Instance>("s1", r1);
            var s2 = new State <Instance>("s2", r2);

            var f1 = new FinalState <Instance>("f1", r1);
            var f2 = new FinalState <Instance>("f2", r2);

            initial.To(ortho);

            i1.To(s1);
            i2.To(s2);

            ortho.To(final);             // This should happen once all regions in ortho are complete?

            s1.To(f1).When <string>(c => c == "complete1");
            s2.To(f2).When <string>(c => c == "complete2");

            ortho.To(simple).When <string>(c => c == "jump");
            simple.To(ortho).When <string>(c => c == "back");

            model.Validate();

            var instance = new Instance("muximise");

            model.Initialise(instance);

            /*
             * console.log("simple.isSimple = " + simple.isSimple());
             * console.log("simple.isComposite = " + simple.isComposite());
             * console.log("simple.isOrthogonal = " + simple.isOrthogonal());
             *
             * console.log("model.isSimple = " + model.isSimple());
             * console.log("model.isComposite = " + model.isComposite());
             * console.log("model.isOrthogonal = " + model.isOrthogonal());
             *
             * console.log("ortho.isSimple = " + ortho.isSimple());
             * console.log("ortho.isComposite = " + ortho.isComposite());
             * console.log("ortho.isOrthogonal = " + ortho.isOrthogonal());
             */

            Trace.Assert(simple.IsSimple);
            Trace.Assert(!model.IsSimple);
            Trace.Assert(!ortho.IsSimple);

            Trace.Assert(!simple.IsComposite);
            Trace.Assert(model.IsComposite);
            Trace.Assert(ortho.IsComposite);

            Trace.Assert(!simple.IsOrthogonal);
            Trace.Assert(!model.IsOrthogonal);
            Trace.Assert(ortho.IsOrthogonal);

            model.Evaluate(instance, "complete1");
            model.Evaluate(instance, "complete2");

            Trace.Assert(model.IsComplete(instance));
        }