本文整理汇总了C#中State.AddTransition方法的典型用法代码示例。如果您正苦于以下问题:C# State.AddTransition方法的具体用法?C# State.AddTransition怎么用?C# State.AddTransition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State.AddTransition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplicationController
public ApplicationController(
Game game,
IGameController gameController,
IInputService inputService)
{
this.game = game;
this.gameController = gameController;
this.inputService = inputService;
var intro = new State<Action<double>>(
"Intro",
null,
delegate
{
this.introGameState = new IntroGameState(this.game);
this.gameStateManager.Push(this.introGameState);
},
() => this.gameStateManager.Pop());
var menu = new State<Action<double>>(
"Menu",
null,
delegate
{
this.menuGameState = new MenuGameState(this.game, this.inputService);
this.gameStateManager.Push(this.menuGameState);
},
() => this.gameStateManager.Pop());
var gameplay = new State<Action<double>>(
"Gameplay",
null,
delegate
{
this.gameplayGameState = new GameplayGameState(this.gameController);
this.gameStateManager.Push(this.gameplayGameState);
},
() => this.gameStateManager.Pop());
var exit = new State<Action<double>>(
"Exit",
null,
() => this.game.Exit(),
null);
intro.AddTransition(menu, () => this.introGameState.IsTransitionAllowed);
menu.AddTransition(gameplay, () => this.menuGameState.IsTransitionAllowed && (string)this.menuGameState.TransitionTag == MenuItems.StartGame);
menu.AddTransition(exit, () => this.menuGameState.IsTransitionAllowed && (string)this.menuGameState.TransitionTag == MenuItems.ExitGame);
gameplay.AddTransition(menu, () => this.gameplayGameState.IsTransitionAllowed);
this.applicationStateMachine = new StateMachine<Action<double>>(intro);
//this.applicationStateMachine = new StateMachine<Action<double>>(gameplay); // Skipping intro and menu for faster startup
}
示例2: Optional
public static Nfa Optional(Nfa nfa)
{
State startState = new State();
startState.AddTransition(new EpsilonTransition(nfa.StartState));
State endState = new State();
nfa.EndState.AddTransition(new EpsilonTransition(endState));
startState.AddTransition(new EpsilonTransition(endState));
return new Nfa(startState, endState);
}
示例3: State_AddTransition_TwoTransitionsWithSameTriggerFromToGuard_ThrowsDuplicateTransitionException
public void State_AddTransition_TwoTransitionsWithSameTriggerFromToGuard_ThrowsDuplicateTransitionException()
{
var state1 = new State<StubStateModel>("s1");
var state2 = new State<StubStateModel>("s2");
Func<StubStateModel, bool> guard = m => true;
var trigger1 = new Trigger("t1");
var transition1 = new Transition<StubStateModel>(trigger1, state1, state2, guard);
var transition2 = new Transition<StubStateModel>(trigger1, state1, state2, guard);
state1.AddTransition(transition1);
Assert.Throws<InvalidTransitionException>(() =>
state1.AddTransition(transition2));
}
示例4: Start
void Start () {
idle = new State(new Action_NoAction(), new Action_ReadyToShoot(), new Action_StartShooting(), "Idle");
firing = new State(new Action_NoAction(), new Action_Shooting(), new Action_StopShooting(), "Firing");
outOfAmmo = new State(new Action_NoAction(), new Action_EmptyClip(), new Action_ReloadTime(), "Out Of Ammo");
reload = new State(new Action_NoAction(), new Action_Reloading(), new Action_FullClip(), "Reload");
idle.AddTransition(new Transition(firing, new Action_NoAction()), "Trigger Pulled");
firing.AddTransition(new Transition(idle, new Action_NoAction()), "Trigger Released");
firing.AddTransition(new Transition(outOfAmmo, new Action_NoAction()), "Empty Clip");
outOfAmmo.AddTransition(new Transition(reload, new Action_NoAction()), "Reloading");
reload.AddTransition(new Transition(idle, new Action_NoAction()), "Reloaded");
stateMachine = ApplyStateMachine.createFSMInstance(idle, new Action_NoAction(), this.gameObject, name);
}
示例5: Match
public static Nfa Match(int symbol)
{
State startState = new State();
State endState = new State();
startState.AddTransition(new MatchRangeTransition(endState, Interval.FromBounds(symbol, symbol)));
return new Nfa(startState, endState);
}
示例6: MatchRange
public static Nfa MatchRange(Interval range)
{
State startState = new State();
State endState = new State();
startState.AddTransition(new MatchRangeTransition(endState, range));
return new Nfa(startState, endState);
}
示例7: MatchAny
public static Nfa MatchAny(params int[] symbols)
{
State startState = new State();
State endState = new State();
foreach (var symbol in symbols)
startState.AddTransition(new MatchRangeTransition(endState, Interval.FromBounds(symbol, symbol)));
return new Nfa(startState, endState);
}
示例8: MakeAnyString
/// <summary>
/// Returns a new (deterministic) automaton that accepts all strings.
/// </summary>
public static Automaton MakeAnyString()
{
Automaton a = new Automaton();
State s = new State();
a.Initial = s;
s.accept = true;
s.AddTransition(new Transition(Character.MIN_CODE_POINT, Character.MAX_CODE_POINT, s));
a.deterministic = true;
return a;
}
示例9: State_Addtransition_SourceDifferentThanState_ThrowsInvalidTransEx
public void State_Addtransition_SourceDifferentThanState_ThrowsInvalidTransEx()
{
var state1 = new State<StubStateModel>("s1");
var state2 = new State<StubStateModel>("s2");
var trigger1 = new Trigger("t1");
var transition1 = new Transition<StubStateModel>(trigger1, state2, state1);
Assert.Throws<InvalidTransitionException>(() =>
state1.AddTransition(transition1));
}
示例10: SetUp
public override void SetUp()
{
base.SetUp();
// build an automaton matching this jvm's letter definition
State initial = new State();
State accept = new State();
accept.Accept = true;
for (int i = 0; i <= 0x10FFFF; i++)
{
if (Character.IsLetter(i))
{
initial.AddTransition(new Transition(i, i, accept));
}
}
Automaton single = new Automaton(initial);
single.Reduce();
Automaton repeat = BasicOperations.Repeat(single);
jvmLetter = new CharacterRunAutomaton(repeat);
}
示例11: StateMachine_Trigger_ValidlyTransitions_RaisesAllEventsInCorrectOrder
public void StateMachine_Trigger_ValidlyTransitions_RaisesAllEventsInCorrectOrder()
{
var calls = new List<string>();
var model = new TrackableStateModel();
var state1 = new State<TrackableStateModel>("s1");
var state2 = new State<TrackableStateModel>("s2");
var trigger = new Trigger("t1");
var transition = new Transition<TrackableStateModel>(trigger, state1, state2);
state1.AddTransition(transition);
model.CurrentState = state1;
var stateMachine = new StateMachine<TrackableStateModel>();
Action<object, TransitionEventArgs<TrackableStateModel>> entering = (s, e) => calls.Add(String.Format("entering {0} from {1} on {2}", e.To, e.From, e.Trigger));
Action<object, TransitionEventArgs<TrackableStateModel>> entered = (s, e) => calls.Add(String.Format("entered {0} from {1} on {2}", e.To, e.From, e.Trigger));
Action<object, TransitionEventArgs<TrackableStateModel>> exiting = (s, e) => calls.Add(String.Format("exiting {0} to {1} on {2}", e.From, e.To, e.Trigger));
Action<object, TransitionEventArgs<TrackableStateModel>> exited = (s, e) => calls.Add(String.Format("exited {0} to {1} on {2}", e.From, e.To, e.Trigger));
model.Setting += (s, e) => calls.Add("setting new current state on model");
state1.Entering += (s, e) => entering(s, e);
state1.Entered += (s, e) => entered(s, e);
state1.Exiting += (s, e) => exiting(s, e);
state1.Exited += (s, e) => exited(s, e);
state2.Entering += (s, e) => entering(s, e);
state2.Entered += (s, e) => entered(s, e);
state2.Exiting += (s, e) => exiting(s, e);
state2.Exited += (s, e) => exited(s, e);
stateMachine.Transitioning += (s, e) => calls.Add(String.Format("transitioning from {0} to {1} on {2}", e.From, e.To, e.Trigger));
stateMachine.Transitioned += (s, e) => calls.Add(String.Format("transitioned from {0} to {1} on {2}", e.From, e.To, e.Trigger));
stateMachine.Trigger(trigger, model);
Assert.Equal(7, calls.Count);
Assert.Equal("transitioning from s1 to s2 on t1", calls[0]);
Assert.Equal("exiting s1 to s2 on t1", calls[1]);
Assert.Equal("entering s2 from s1 on t1", calls[2]);
Assert.Equal("setting new current state on model", calls[3]);
Assert.Equal("exited s1 to s2 on t1", calls[4]);
Assert.Equal("entered s2 from s1 on t1", calls[5]);
Assert.Equal("transitioned from s1 to s2 on t1", calls[6]);
}
示例12: MakeString
public static Automaton MakeString(int[] word, int offset, int length)
{
Automaton a = new Automaton();
a.Deterministic = true;
State s = new State();
a.Initial = s;
for (int i = offset; i < offset + length; i++)
{
State s2 = new State();
s.AddTransition(new Transition(word[i], s2));
s = s2;
}
s.accept = true;
return a;
}
示例13: MakeCharRange
/// <summary>
/// Returns a new (deterministic) automaton that accepts a single codepoint whose
/// value is in the given interval (including both end points).
/// </summary>
public static Automaton MakeCharRange(int min, int max)
{
if (min == max)
{
return MakeChar(min);
}
Automaton a = new Automaton();
State s1 = new State();
State s2 = new State();
a.Initial = s1;
s2.accept = true;
if (min <= max)
{
s1.AddTransition(new Transition(min, max, s2));
}
a.deterministic = true;
return a;
}
示例14: AnyOfRightLength
/// <summary>
/// Constructs sub-automaton corresponding to decimal numbers of length x.Substring(n).Length.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="n">The n.</param>
/// <returns></returns>
private static State AnyOfRightLength(string x, int n)
{
var s = new State();
if (x.Length == n)
{
s.Accept = true;
}
else
{
s.AddTransition(new Transition('0', '9', AnyOfRightLength(x, n + 1)));
}
return s;
}
示例15: Build
private void Build(State start, State end, UTF8Sequence startUTF8, UTF8Sequence endUTF8, int upto)
{
// Break into start, middle, end:
if (startUTF8.ByteAt(upto) == endUTF8.ByteAt(upto))
{
// Degen case: lead with the same byte:
if (upto == startUTF8.Len - 1 && upto == endUTF8.Len - 1)
{
// Super degen: just single edge, one UTF8 byte:
start.AddTransition(new Transition(startUTF8.ByteAt(upto), endUTF8.ByteAt(upto), end));
return;
}
else
{
Debug.Assert(startUTF8.Len > upto + 1);
Debug.Assert(endUTF8.Len > upto + 1);
State n = NewUTF8State();
// Single value leading edge
start.AddTransition(new Transition(startUTF8.ByteAt(upto), n)); // type=single
// Recurse for the rest
Build(n, end, startUTF8, endUTF8, 1 + upto);
}
}
else if (startUTF8.Len == endUTF8.Len)
{
if (upto == startUTF8.Len - 1)
{
start.AddTransition(new Transition(startUTF8.ByteAt(upto), endUTF8.ByteAt(upto), end)); // type=startend
}
else
{
Start(start, end, startUTF8, upto, false);
if (endUTF8.ByteAt(upto) - startUTF8.ByteAt(upto) > 1)
{
// There is a middle
All(start, end, startUTF8.ByteAt(upto) + 1, endUTF8.ByteAt(upto) - 1, startUTF8.Len - upto - 1);
}
End(start, end, endUTF8, upto, false);
}
}
else
{
// start
Start(start, end, startUTF8, upto, true);
// possibly middle, spanning multiple num bytes
int byteCount = 1 + startUTF8.Len - upto;
int limit = endUTF8.Len - upto;
while (byteCount < limit)
{
// wasteful: we only need first byte, and, we should
// statically encode this first byte:
TmpUTF8a.Set(StartCodes[byteCount - 1]);
TmpUTF8b.Set(EndCodes[byteCount - 1]);
All(start, end, TmpUTF8a.ByteAt(0), TmpUTF8b.ByteAt(0), TmpUTF8a.Len - 1);
byteCount++;
}
// end
End(start, end, endUTF8, upto, true);
}
}