public void Init() { // Initialize the states, adding them to the FSM and configuring their behaviour fsm.Add(Season.Winter) .Expires(3f) .GoesTo(Season.Spring) .OnEnter(() => Console.ForegroundColor = ConsoleColor.White) .OnLeave(() => Console.WriteLine("Winter is ending...")) .Calls(d => Console.WriteLine("Winter is going on.. {0}%", d.StateProgress * 100f)); fsm.Add(Season.Spring) .Expires(3f) .GoesTo(Season.Summer) .OnEnter(() => Console.ForegroundColor = ConsoleColor.Green) .OnLeave(() => Console.WriteLine("Spring is ending...")) .Calls(d => Console.WriteLine("Spring is going on.. {0}%", d.StateProgress * 100f)); fsm.Add(Season.Summer) .Expires(3f) .GoesTo(Season.Fall) .OnEnter(() => Console.ForegroundColor = ConsoleColor.Red) .OnLeave(() => Console.WriteLine("Summer is ending...")) .Calls(d => Console.WriteLine("Summer is going on.. {0}%", d.StateProgress * 100f)); fsm.Add(Season.Fall) .Expires(3f) .GoesTo(Season.Winter) .OnEnter(() => Console.ForegroundColor = ConsoleColor.DarkYellow) .OnLeave(() => Console.WriteLine("Fall is ending...")) .Calls(d => Console.WriteLine("Fall is going on.. {0}%", d.StateProgress * 100f)); // Very important! set the starting state fsm.CurrentState = Season.Winter; }
private void InitStates() { State = new FSM <EnemyState, BaseEnemyAIState>(); _idleState = new EnemyIdleState(this); _chaseState = new EnemyChaseState(this); State.Add(EnemyState.IDLE, _idleState); State.Add(EnemyState.CHASE, _chaseState); State.SetState(EnemyState.IDLE); }
// Start is called before the first frame update void Start() { Pieces = transform.Find("Cube Group"); piecePositions = GetInitialPositions(Pieces); //FINALLY after declaring the state classes //create the three states and add them to the fsm m_fsm.Add((int)GameStates.SETUP, new Setup(m_fsm, this)); m_fsm.Add((int)GameStates.PLAY, new Play(m_fsm, this)); m_fsm.Add((int)GameStates.CLEANUP, new Setup(m_fsm, this, Setup.MoveType.MOVE_OUT)); //set the states of the fsm m_fsm.SetCurrentState(m_fsm.GetState((int)GameStates.SETUP)); }
public void Init(LevelData data) { _data = data; InitParameters(); mode = new FSM <LEVEL_WIN_MODE, LevelMode>(); mode.Add(LEVEL_WIN_MODE.MAX_SCORE_MODE, new ScoreLevelMode(this)); mode.Add(LEVEL_WIN_MODE.TIMER_MODE, new TimeLevelMode(this)); mode.SetState(data.levelMode); Hero.onDefeat += OnHeroDefeat; EventManager.Get <AddScoreEvent>().Subscribe(OnAddScoreEvent); }
public PlatformModel(PlatformConfig config) { _config = config; fsm = new FSM <PlatformState, BasePlatformState>(); /*fsm.Add(new UpState(_config.upStateDuration)); * fsm.Add(new DownState(_config.downStateDuration));*/ fsm.Add(new BasePlatformState(PlatformState.Up, PlatformState.Down, _config.upStateDuration)); fsm.Add(new BasePlatformState(PlatformState.Down, PlatformState.Appear, _config.downStateDuration)); fsm.Add(new BasePlatformState(PlatformState.Appear, PlatformState.Up, _config.highlightDuration)); fsm.OnStateChanged += OnStateChanged; }
// Use this for initialization void Start() { brain = new FSM(); brain.Add(Wander); idleTime = -1; }
public XmasLogBehaviour1(Boss boss) : base(boss) { // State machine _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour1"); var targetingInitialPositionBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition) .OnUpdate(TargetingInitialPositionTaskUpdate); var shootingPatternBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.ShootingPattern) .OnEnter(ShootingPatternTaskEnter); _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour); _stateMachine.Add(BehaviourState.ShootingPattern, shootingPatternBehaviour); }
public XmasSnowmanBehaviour4(Boss boss) : base(boss) { // State machine _stateMachine = new FSM <BehaviourState>("xmas-snowman-behaviour4"); var targetingInitialPositionBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition) .OnUpdate(TargetingInitialPositionTaskUpdate); var hatAttackBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.HatAttack) .OnEnter(HatAttackTaskEnter) .OnUpdate(HatAttackTaskUpdate); _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour); _stateMachine.Add(BehaviourState.HatAttack, hatAttackBehaviour); }
public XmasLogBehaviour2(Boss boss) : base(boss) { // State machine _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour2"); var targetingScreenCenterBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingScreenCenter) .OnUpdate(TargetingScreenCenterTaskUpdate); var shootingPatternBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.HelicopterPattern) .OnEnter(HelicopterPatternTaskEnter) .OnUpdate(HelicopterPatternTaskUpdate); _stateMachine.Add(BehaviourState.TargetingScreenCenter, targetingScreenCenterBehaviour); _stateMachine.Add(BehaviourState.HelicopterPattern, shootingPatternBehaviour); }
public XmasSnowmanBehaviour3(Boss boss) : base(boss) { // State machine _stateMachine = new FSM <BehaviourState>("xmas-snowman-behaviour3"); var targetingInitialPositionBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition) .OnUpdate(TargetingInitialPositionTaskUpdate); var carrotShotBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.CarrotShot) .OnEnter(CarrotShotTaskEnter) .OnUpdate(CarrotShotTaskUpdate); _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour); _stateMachine.Add(BehaviourState.CarrotShot, carrotShotBehaviour); }
private void InitStates() { State = new FSM <SwipeState, SwipeAbstractState>(); _idleState = new SwipeIdleState(this); _touchedState = new SwipeTouchedState(this); _touchedState.moveThreshold = moveThreshold; _touchedState.swipeThreshold = swipeThreshold; _touchedState.straightness = straightness; _untouchedState = new SwipeUntouchedState(this); _untouchedState.moveThreshold = moveThreshold; _untouchedState.straightness = straightness; State.Add(SwipeState.IDLE, _idleState); State.Add(SwipeState.TOUCHED, _touchedState); State.Add(SwipeState.UNTOUCHED, _untouchedState); }
public XmasLogBehaviour3(Boss boss) : base(boss) { // State machine _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour3"); var targetingInitialPositionBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition) .OnUpdate(TargetingInitialPositionTaskUpdate); var babyLogBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.BabyLogs) .OnEnter(BabyLogTaskEnter) .OnUpdate(BabyLogTaskUpdate); _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour); _stateMachine.Add(BehaviourState.BabyLogs, babyLogBehaviour); _babyLogs = new List <BabyLog>(); }
public void Idle() { if (idleTime == -1) { idleTime = Random.Range(5.0f, 25.0f); } // Play Idle animation if (brain.timer > idleTime) { idleTime = -1; brain.Pop(); brain.Add(Wander); } if (CanPlayerBeSeen()) { idleTime = -1; brain.Add(Chase); } }
public XmasLogBehaviour4(Boss boss) : base(boss) { // State machine _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour4"); var targetingInitialPositionBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition) .OnUpdate(TargetingInitialPositionTaskUpdate); var removingHollyBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.HollyAttack) .OnEnter(RemovingHollyTaskEnter); var hollyAttackBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.HollyAttack) .OnEnter(HollyAttackTaskEnter) .OnUpdate(HollyAttackTaskUpdate); _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour); _stateMachine.Add(BehaviourState.RemovingHolly, removingHollyBehaviour); _stateMachine.Add(BehaviourState.HollyAttack, hollyAttackBehaviour); }
public void SnapshotRestore() { FSM <int> F = new FSM <int>(""); F.Add(1) .Expires(5) .GoesTo(2); F.Add(2); F.CurrentState = 1; F.Process(0f); Assert.AreEqual(1, F.CurrentState); F.Process(1f); Assert.AreEqual(1, F.CurrentState); F.Process(2f); Assert.AreEqual(1, F.CurrentState); var snap = F.SaveSnapshot(); F.Process(3f); Assert.AreEqual(1, F.CurrentState); F.Process(4f); Assert.AreEqual(1, F.CurrentState); F.Process(5.1f); Assert.AreEqual(2, F.CurrentState); F.RestoreSnapshot(snap); Assert.AreEqual(1, F.CurrentState); F.Process(3f); Assert.AreEqual(1, F.CurrentState); F.Process(4f); Assert.AreEqual(1, F.CurrentState); F.Process(5.1f); Assert.AreEqual(2, F.CurrentState); }
public void OnEnterAndOnLeaveHandlers() { FSM <int> F = new FSM <int>(""); RefContainer <int> x = new RefContainer <int>(); F.Add(1) .Expires(5) .GoesTo(2) .OnLeave(() => x.Value += 15); F.Add(2) .OnEnter(() => x.Value *= 2); F.CurrentState = 1; F.Process(0f); F.Process(5.1f); Assert.AreEqual(30, x.Value); F.Process(5.2f); Assert.AreEqual(30, x.Value); F.Process(5.3f); Assert.AreEqual(30, x.Value); F.Process(5.4f); Assert.AreEqual(30, x.Value); }
public void StateIsLeavedImmediatelyOnSuddenExpiration() { FSM <int> F = new FSM <int>(""); RefContainer <int> x = new RefContainer <int>(); F.Add(1) .Expires(1) .GoesTo(2); F.Add(2) .GoesTo(3) .Expires(1) .OnLeave(() => x.Value += 15); F.Add(3) .OnEnter(() => x.Value *= 2); F.CurrentState = 1; F.Process(0f); F.Process(1.5f); F.Process(3f); Assert.AreEqual(3, F.CurrentState); Assert.AreEqual(30, x.Value); }
public void SimpleExpiration() { FSM <int> F = new FSM <int>(""); F.Add(1) .Expires(5) .GoesTo(2); F.Add(2); F.CurrentState = 1; F.Process(0f); Assert.AreEqual(1, F.CurrentState); F.Process(1f); Assert.AreEqual(1, F.CurrentState); F.Process(2f); Assert.AreEqual(1, F.CurrentState); F.Process(3f); Assert.AreEqual(1, F.CurrentState); F.Process(4f); Assert.AreEqual(1, F.CurrentState); F.Process(5.1f); Assert.AreEqual(2, F.CurrentState); }
public XmasSnowmanBehaviour1(Boss boss) : base(boss) { InitialBehaviourLife = GameConfig.BossDefaultBehaviourLife * 0.5f; // State machine _stateMachine = new FSM <BehaviourState>("xmas-snowman-behaviour1"); var targetingInitialPositionBehaviour = new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition) .OnEnter(TargetingInitialPositionTaskEnter) .OnUpdate(TargetingInitialPositionTaskUpdate) .OnExit(TargetingInitialPositionTaskExit); _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour); _initialBehaviourPosition = new Vector2(Boss.InitialPosition.X, Boss.InitialPosition.Y + 500); }
public void Start() { m_StartWait = new WaitForSeconds(m_StartDelay); m_EndWait = new WaitForSeconds(m_EndDelay); m_Tanks = new List <GameObject>(); GameStart = false; m_Fsm.Add((int)GameManagerStateEnum.DISCONNECT, new DisconnectState(m_Fsm, this)); m_Fsm.Add((int)GameManagerStateEnum.WAITING_PLAYER, new WaitingPlayerState(m_Fsm, this)); m_Fsm.Add((int)GameManagerStateEnum.NOT_READY, new NotReadyState(m_Fsm, this)); m_Fsm.Add((int)GameManagerStateEnum.WAITING_ALL_READY, new WaitingAllReadyState(m_Fsm, this)); m_Fsm.Add((int)GameManagerStateEnum.PLAYING, new PlayingState(m_Fsm, this)); m_Fsm.Add((int)GameManagerStateEnum.FINISH_PLAY, new FinishPlayState(m_Fsm, this)); m_Fsm.SetCurrentState(m_Fsm.GetState((int)GameManagerStateEnum.DISCONNECT)); }
private static void Main(string[] args) { fsm = new FSM <char>("start"); fsm.Add("start", '+', null, "whole"); fsm.Add("start", '-', c => fsm.Variables.sign = -1, "whole"); fsm.Add("start", char.IsDigit, AddChar, "whole"); fsm.Add("start", '.', c => fsm.Variables.divisor = 0.1, "fract"); fsm.Add("whole", char.IsDigit, AddChar); fsm.Add("whole", '.', c => fsm.Variables.divisor = 0.1, "fract"); fsm.Add("fract", char.IsDigit, c => { fsm.Variables.number += fsm.Variables.divisor * (c - '0'); fsm.Variables.divisor /= 10; }); fsm.OnStart = () => { fsm.Variables.sign = 1; fsm.Variables.number = 0.0; fsm.Variables.divisor = 0.0; }; Verify(); do { Console.Write("Enter a number: "); var s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) { break; } fsm.Restart(); foreach (var c in s) { fsm.Handle(c); } Console.WriteLine("The number is " + fsm.Variables.sign * fsm.Variables.number); } while (true); }
private static void Main(string[] args) { fsm = new FSM<char>("start"); fsm.Add("start", '+', null, "whole"); fsm.Add("start", '-', c => fsm.Variables.sign = -1, "whole"); fsm.Add("start", char.IsDigit, AddChar, "whole"); fsm.Add("start", '.', c => fsm.Variables.divisor = 0.1, "fract"); fsm.Add("whole", char.IsDigit, AddChar); fsm.Add("whole", '.', c => fsm.Variables.divisor = 0.1, "fract"); fsm.Add("fract", char.IsDigit, c => { fsm.Variables.number += fsm.Variables.divisor * (c - '0'); fsm.Variables.divisor /= 10; }); fsm.OnStart = () => { fsm.Variables.sign = 1; fsm.Variables.number = 0.0; fsm.Variables.divisor = 0.0; }; Verify(); do { Console.Write("Enter a number: "); var s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) break; fsm.Restart(); foreach (var c in s) fsm.Handle(c); Console.WriteLine("The number is " + fsm.Variables.sign * fsm.Variables.number); } while (true); }
private void SetUp() { fsm.OnStart = () => { sign = 1; number = 0.0; divisor = 0.0; }; fsm.Add("start", '+', null, "whole"); fsm.Add("start", '-', _ => sign = -1, "whole"); fsm.Add("start", char.IsDigit, AddChar, "whole"); fsm.Add("start", '.', _ => divisor = 0.1, "fract"); fsm.Add("whole", char.IsDigit, AddChar); fsm.Add("whole", '.', _ => divisor = 0.1, "fract"); fsm.Add("fract", char.IsDigit, c => { number += divisor * (c - '0'); divisor /= 10; }); }
/// <summary> /// Queues a new state to specified FSM. /// </summary> /// <param name="fsm">The FSM.</param> /// <returns>The newly created state.</returns> public static FsmStateBehaviour <sbyte> Queue(this FSM <sbyte> fsm) { return(fsm.Add((sbyte)fsm.Count) .GoesTo((sbyte)(fsm.Count + 1))); }
/// <summary> /// Queues a new state to specified FSM. /// </summary> /// <param name="fsm">The FSM.</param> /// <returns>The newly created state.</returns> public static FsmStateBehaviour <ushort> Queue(this FSM <ushort> fsm) { return(fsm.Add((ushort)fsm.Count) .GoesTo((ushort)(fsm.Count))); }
/// <summary> /// Queues a new state to specified FSM. /// </summary> /// <param name="fsm">The FSM.</param> /// <returns>The newly created state.</returns> public static FsmStateBehaviour <ulong> Queue(this FSM <ulong> fsm) { return(fsm.Add((ulong)fsm.Count) .GoesTo((ulong)(fsm.Count))); }
/// <summary> /// Queues a new state to specified FSM. /// </summary> /// <param name="fsm">The FSM.</param> /// <returns>The newly created state.</returns> public static FsmStateBehaviour <int> Queue(this FSM <int> fsm) { return(fsm.Add(fsm.Count) .GoesTo(fsm.Count)); }
/// <summary> /// Queues a new state to specified FSM. /// </summary> /// <param name="fsm">The FSM.</param> /// <returns>The newly created state.</returns> public static FsmStateBehaviour <char> Queue(this FSM <char> fsm) { return(fsm.Add((char)fsm.Count) .GoesTo((char)(fsm.Count + 1))); }
public virtual void Register() { fsm.Add(CharState.IDLE, EnterIdle, RunIdle, ExitIdle); fsm.Add(CharState.ATTACK, EnterAttack, RunAttack, ExitAttack); fsm.SetState(CharState.IDLE); }
public override void Init() { fsm.Add("sayhello", Hello); fsm.Add("saygoodbye", Doei); }
public BaseSheepModel() { _fsm = new FSM <SheepState, BaseState <SheepState> >(); _fsm.Add(new BaseSheepState(SheepState.Death)); _fsm.OnStateChanged += OnStateChanged; }