当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.Initialise方法代码示例

本文整理汇总了C#中StateMachine.Initialise方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.Initialise方法的具体用法?C# StateMachine.Initialise怎么用?C# StateMachine.Initialise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateMachine的用法示例。


在下文中一共展示了StateMachine.Initialise方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

		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);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:25,代码来源:Else.cs

示例2: Run

		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));
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:29,代码来源:Transitions.cs

示例3: Run

		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));
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:31,代码来源:History.cs

示例4: Run

		public static void Run () {

			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var junction1 = new PseudoState<Instance>("junction1", model, PseudoStateKind.Junction);
			var junction2 = new PseudoState<Instance>("junction2", model, PseudoStateKind.Junction);

			var pass = new State<Instance>("success", model);
			var fail = new State<Instance>("error", model);

			initial.To(junction1);

			junction1.To(junction2).When(i => i.Int1 == 0).Effect(i => i.Int1++);
			junction1.To(fail).Else();
			junction2.To(pass).When(i => i.Int1 == 0).Effect(i => i.Int1++);
			junction2.To(fail).Else();

			model.Validate();

			var instance = new Instance("static");

			model.Initialise(instance);

			Trace.Assert(pass == instance.GetCurrent(model.DefaultRegion));

			Trace.Assert(2 == instance.Int1);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:27,代码来源:Static.cs

示例5: Run

		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var target = new State<Instance>("state", model).Entry(i => i.Int1++).Exit(i => i.Int2++);

			initial.To(target);

			target.To().When<string>(m => m == "internal").Effect(i => i.Int3++);
			target.To(target).When<string>(m => m == "external").Effect(i => i.Int3++);

			var instance = new Instance("internal");

			model.Validate();

			model.Initialise(instance);

			model.Evaluate(instance, "internal");

			Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
			Trace.Assert(1 == instance.Int1);
			Trace.Assert(0 == instance.Int2);
			Trace.Assert(1 == instance.Int3);

			model.Evaluate(instance, "external");

			Trace.Assert(target == instance.GetCurrent(model.DefaultRegion));
			Trace.Assert(2 == instance.Int1);
			Trace.Assert(1 == instance.Int2);
			Trace.Assert(2 == instance.Int3);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:30,代码来源:Internal.cs

示例6: Run

		public static void Run () {

			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var stateA = new State<Instance>("stateA", model);
			var choice = new PseudoState<Instance>("choice", model, PseudoStateKind.Choice);

			initial.To(stateA);

			stateA.To(choice).When<string>(message => message == "choose");

			choice.To(stateA).Effect(instance => instance.Int1++);
			choice.To(stateA).Effect(instance => instance.Int2++);
			choice.To(stateA).Effect(instance => instance.Int3++);

			model.Validate();

			var instance1 = new Instance("instance1");

			model.Initialise(instance1);

			for (var i = 0; i < 99; i++) {
				model.Evaluate(instance1, "choose");
			}

			Trace.Assert(99 == (instance1.Int1 + instance1.Int2 + instance1.Int3));

			Runtime.Extensions.RandomSelector = randRobin;

			var instance2 = new Instance("instance2");

			model.Initialise(instance2);

			for (var i = 0; i < 99; i++) {
				model.Evaluate(instance2, "choose");
			}

			model.Evaluate(instance2, "end");

			Trace.Assert(33 == instance2.Int1);
			Trace.Assert(33 == instance2.Int2);
			Trace.Assert(33 == instance2.Int3);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:43,代码来源:Choice.cs

示例7: Test

		public static void Test()
		{
			var stateMachine = new StateMachine<State>( "external" );
			var region = stateMachine.CreateRegion( "external" );

			var initial = region.CreatePseudoState( "initial", PseudoStateKind.Initial );
			var composite = region.CreateCompositeState( "composite" );
			var orthogonal = region.CreateOrthogonalState( "orthogonal" );
			var final = region.CreateFinalState( "final" );

			var c1 = composite.CreateSimpleState( "c1" );
			var c2 = composite.CreateSimpleState( "c2" );
		
			var region1 = orthogonal.CreateRegion( "region1" );
			var region2 = orthogonal.CreateRegion( "region2" );

			var o1 = region1.CreateSimpleState( "o1" );
			var o2 = region2.CreateSimpleState( "o2" );

			var j1 = region2.CreatePseudoState( "junction", PseudoStateKind.Junction );

			stateMachine.CreateTransition( initial, composite );
			stateMachine.CreateTransition( composite.CreatePseudoState( "initial", PseudoStateKind.Initial ), c1 );
			stateMachine.CreateTransition<String>( c2, c1, ( state, command ) => command == "1" );
			stateMachine.CreateTransition<String>( c1, j1, ( state, command ) => command == "2" );
			stateMachine.CreateElse( j1, o1 );
			stateMachine.CreateTransition<String>( o1, o2, ( state, command ) => command == "3" );
			stateMachine.CreateTransition<String>( o2, c2, ( state, command ) => command == "4" );
			stateMachine.CreateTransition<String>( composite, orthogonal, ( state, command ) => command == "5" );
			stateMachine.CreateTransition<String>( composite, final, ( state, command ) => command == "x" );

			stateMachine.CreateTransition( region1.CreatePseudoState( "initial", PseudoStateKind.Initial ), o1 );
			stateMachine.CreateTransition( region2.CreatePseudoState( "initial", PseudoStateKind.Initial ), o2 );

			var instance = new State();

			stateMachine.Initialise( instance );

			Trace.Assert( !stateMachine.Process( instance, "1" ) );
			Trace.Assert( stateMachine.Process( instance, "2" ) );
			Trace.Assert( !stateMachine.Process( instance, "4" ) );
			Trace.Assert( stateMachine.Process( instance, "3" ) );
			Trace.Assert( stateMachine.Process( instance, "4" ) );
			Trace.Assert( stateMachine.Process( instance, "1" ) );
			Trace.Assert( !stateMachine.Process( instance, "z" ) );
			Trace.Assert( stateMachine.Process( instance, "x" ) );
			Trace.Assert( stateMachine.IsComplete( instance ) );
		}
开发者ID:rezn,项目名称:state.cs,代码行数:48,代码来源:External.cs

示例8: Run

		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var state1 = new State<Instance>("state1", model);
			var state2 = new State<Instance>("state2", model);

			var regionA = new Region<Instance>("regionA", state1);
			var initialA = new PseudoState<Instance>("initialA", regionA, PseudoStateKind.Initial);
			var state3 = new State<Instance>("state3", regionA);
			var state8 = new State<Instance>("state8", regionA);

			var regionB = new Region<Instance>("regionB", state1);
			var initialB = new PseudoState<Instance>("initialB", regionB, PseudoStateKind.Initial);
			var state4 = new State<Instance>("state4", regionB);
			var state5 = new State<Instance>("state5", regionB);

			var regionBa = new Region<Instance>("regionBa", state4);
			var initialBa = new PseudoState<Instance>("initialBa", regionBa, PseudoStateKind.Initial);
			var state6 = new State<Instance>("state6", regionBa);

			var regionBb = new Region<Instance>("regionBb", state4);
			var initialBb = new PseudoState<Instance>("initialBb", regionBb, PseudoStateKind.Initial);
			var state7 = new State<Instance>("state7", regionBb);

			initial.To(state1);
			initialA.To(state3);
			initialB.To(state4);
			initialBa.To(state6);
			initialBb.To(state7);

			state3.To(state2).When<string>(c => c == "event2");
			state3.To(state8).When<string>(c => c == "event1");
			state7.To(state5).When<string>(c => c == "event2");
			state7.To(state5).When<string>(c => c == "event1");

			model.Validate();

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

			model.Evaluate(instance, "event2");

			Trace.Assert(state2 == instance.GetCurrent(model.DefaultRegion), instance.GetCurrent(model.DefaultRegion).ToString() );
			Trace.Assert(state4 == instance.GetCurrent(regionB));
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:45,代码来源:p3pp3r.cs

示例9: Run

		public static void Run () {
			var model = new StateMachine<StateMachineInstance>("Model");
			var initial = model.CreatePseudoState("Initial", PseudoStateKind.Initial);
			var on = model.CreateState("On");
			var off = model.CreateState("Off");
			var clean = model.CreateState("Clean");
			var final = model.CreateFinalState("Final");

			var history = on.CreatePseudoState("History", PseudoStateKind.ShallowHistory);
			var idle = on.CreateState("Idle");
			var moveItem = on.CreateState("MoveItem");
			var showItemMovePattern = on.CreateState("ShowItemMovePattern");
			var hideItemMovePattern = on.CreateState("HideItemMovePattern");

			initial.To(idle);
			on.To(clean).When<string>(s => s == "DestroyInput");
			off.To(clean).When<string>(s => s == "DestroyInput");
			on.To(off).When<string>(s => s == "Disable");
			off.To(history).When<string>(s => s == "Enable");
			clean.To(final);
			idle.To(moveItem).When<string>(s => s == "TransformInput");
			moveItem.To(idle).When<string>(s => s == "ReleaseInput");
			idle.To(showItemMovePattern).When<string>(s => s == "ReleaseInput");
			showItemMovePattern.To(hideItemMovePattern).When<string>(s => s == "ReleaseInput");
			hideItemMovePattern.To(idle);

			model.Validate();

			var instance = new StateMachineInstance("instance");

			model.Initialise(instance);

			model.Evaluate(instance, "ReleaseInput");
			model.Evaluate(instance, "Disable");
			model.Evaluate(instance, "Enable");

			Trace.Assert(instance.GetCurrent(on.DefaultRegion) == showItemMovePattern, "History semantics should set current state to " + showItemMovePattern.Name);

			model.Evaluate(instance, "ReleaseInput");
			model.Evaluate(instance, "Disable");
			model.Evaluate(instance, "Enable");

			Trace.Assert(instance.GetCurrent(on.DefaultRegion) == idle, "History semantics should set current state to " + idle.Name);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:44,代码来源:Florent.cs

示例10: Run

		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model);
			var stateA = new State<Instance>("stateA", model);
			var terminate = new PseudoState<Instance>("terminate", model, PseudoStateKind.Terminate);

			initial.To(stateA);
			stateA.To(terminate).When<string>(message => message == "1");

			model.Validate();

			var instance = new Instance("terminate");

			model.Initialise(instance);

			Trace.Assert(!model.Evaluate(instance, "2"));
			Trace.Assert(model.Evaluate(instance, "1"));
			Trace.Assert(!model.Evaluate(instance, "1"));
			Trace.Assert(instance.IsTerminated);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:20,代码来源:Terminate.cs

示例11: Run

		public static void Run () {
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var stateA = new State<Instance>("stateA", model).Exit(i => i.Int1 += 1);
			var stateB = new State<Instance>("stateB", model).Entry(i => i.Int1 += 2);

			initial.To(stateA);
			stateA.To(stateB).When<string>(message => message == "move").Effect(i => i.Int1 += 4);

			model.Validate();

			var instance = new Instance("callbacks");

			model.Initialise(instance);

			model.Evaluate(instance, "move");

			Trace.Assert(1 == (1 & instance.Int1));
			Trace.Assert(2 == (2 & instance.Int1));
			Trace.Assert(4 == (4 & instance.Int1));
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:21,代码来源:Callbacks.cs

示例12: Run

		public static void Run () {
			// create the state machine model elements
			var model = new StateMachine<Instance>("model");
			var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var stateA = new State<Instance>("stateA", model);
			var stateB = new State<Instance>("stateB", model).Exit(i => i.Int1++);

			var bInitial = new PseudoState<Instance>("bInitial", stateB);
			var bStateI = new State<Instance>("bStateI", stateB);
			var bStateII = new State<Instance>("bStateII", stateB);

			// create the state machine model transitions
			initial.To(stateA);
			stateA.To(stateB).When<string>(message => message == "move");

			bInitial.To(bStateI);

			stateB.To(bStateII, TransitionKind.Local).When<string>(message => message == "local");
			stateB.To(bStateII, TransitionKind.External).When<string>(message => message == "external");
			model.Validate();

			// create a state machine instance
			var instance = new Instance("local");

			// initialise the model and instance
			model.Initialise(instance);

			// send the machine instance a message for evaluation, this will trigger the transition from stateA to stateB
			model.Evaluate(instance, "move");

			model.Evaluate(instance, "local");

			Trace.Assert(0 == instance.Int1);

			model.Evaluate(instance, "external");

			Trace.Assert(1 == instance.Int1);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:38,代码来源:Local.cs

示例13: Run

		public static void Run () {

			var model = new StateMachine<Instance>("model");
			var initial1 = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
			var myComposite1 = new State<Instance>("composite1", model);
			var state3 = new State<Instance>("state3", model);
			var initial2 = new PseudoState<Instance>("initial", myComposite1, PseudoStateKind.Initial);
			var state1 = new State<Instance>("state1", myComposite1);
			var state2 = new State<Instance>("state2", myComposite1);

			initial1.To(myComposite1);
			initial2.To(state1);
			myComposite1.To(state3).When<string>(c => c == "a");
			state1.To(state2).When<string>(c => c == "a");

			model.Validate();

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

			model.Evaluate(instance, "a");

			Trace.Assert(instance.GetCurrent(myComposite1.DefaultRegion) == state2);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:24,代码来源:Brice.cs

示例14: Main

		static void Main () {
			// create the state machine model
			var model = new StateMachine<Player>("model");

			// create the vertices within the model
			var initial = model.CreatePseudoState("initial", PseudoStateKind.Initial);
			var operational = model.CreateState("operational");
			var choice = model.CreatePseudoState("choice", PseudoStateKind.Choice);
			var flipped = model.CreateState("flipped");
			var final = model.CreateFinalState("final");

			var history = operational.CreatePseudoState("history", PseudoStateKind.DeepHistory);
			var stopped = operational.CreateState("stopped");
			var active = operational.CreateState("active").Entry(i => i.EngageHead()).Exit(i => i.DisengageHead());

			var running = active.CreateState("running").Entry(i => i.StartMotor()).Exit(i => i.StopMotor());
			var paused = active.CreateState("paused");

			// create the transitions between vertices of the model
			initial.To(operational).Effect(i => i.DisengageHead()).Effect(i => i.StopMotor());
			history.To(stopped);
			stopped.To(running).When<string>(command => command == "play");
			active.To(stopped).When<string>(command => command == "stop");
			running.To(paused).When<string>(command => command == "pause");
			running.To().When<string>(command => command == "tick").Effect((Player instance) => instance.Count++);
			paused.To(running).When<string>(command => command == "play");
			operational.To(final).When<string>(command => command == "off");
			operational.To(choice).When<string>(command => command == "rand");
			choice.To(operational).Effect(() => Console.WriteLine("- transition A back to operational"));
			choice.To(operational).Effect(() => Console.WriteLine("- transition B back to operational"));
			operational.To(flipped).When<string>(command => command == "flip");
			flipped.To(operational).When<string>(command => command == "flip");

			// validate the model for correctness
			model.Validate();

			// create a blocking collection make events from multiple sources thread-safe
			var queue = new System.Collections.Concurrent.BlockingCollection<Object>();

			// create an instance of the player - enqueue a tick message for the machine while its playing
			var player = new Player(() => queue.Add("tick"));

			// initialises the players initial state (enters the region for the first time, causing transition from the initial PseudoState)
			model.Initialise(player);

			// create a task to capture commands from the console in another thread
			System.Threading.Tasks.Task.Run(() => {
				string command = "";

				while (command.Trim().ToLower() != "exit") {
					queue.Add(command = Console.ReadLine());
				}

				queue.CompleteAdding();
			});

			// write the initial command prompt
			Console.Write("{0:0000}> ", player.Count);

			// process messages from the queue
			foreach (var message in queue.GetConsumingEnumerable()) {
				// process the message
				model.Evaluate(player, message);

				// manage the command prompt
				var left = Math.Max(Console.CursorLeft, 6);
				var top = Console.CursorTop;
				Console.SetCursorPosition(0, top);
				Console.Write("{0:0000}>", player.Count);
				Console.SetCursorPosition(left, top);
			}
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:72,代码来源:Program.cs

示例15: Run

		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));
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:68,代码来源:Muximise.cs


注:本文中的StateMachine.Initialise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。