void checkState()
 {
     if (_transitions != null)
         _transitions = null;
     switch(_fsm.state)
     {
         case GameStates.e_intit:
             {
                 _transitions += InitToRunning;
                 break;
             }
         case GameStates.e_running:
             {
                 Time.timeScale = 1;
                 _transitions += RunningToPause;
                 break;
             }
         case GameStates.e_pause:
             {
                 Time.timeScale = 0;
                 _transitions += PauseToRunning;
                 _transitions += PauseToExit;
                 break;
             }
         case GameStates.e_exit:
             {
                 Application.Quit();
                 break;
             }
         default:
             break;
     }
     _transitions();
 }
    private Audio_BGM bgm;             //bgm object

    // Use this for initialization
    void Start()
    {
        //access self, transitions and bgm

        transition = self.GetComponent<Transitions>();  //returns a sample script of Transitions into the script
        bgm = self.GetComponent<Audio_BGM>().GetInstance(); //returns the actual Audio_BGM script
        bgm.PlayTrack(0);   //play the track
    }
 public BuildStatusConfig()
 {
     Settings    = new Settings();
     Schedules   = new Schedules();
     Controllers = new Controllers();
     Monitors    = new Monitors();
     Visualisers = new Visualisers();
     Transitions = new Transitions();
 }
Exemple #4
0
        public new MachineDetermined RenameToNormalNames(string startsWith)
        {
            startsWith ??= "q";

            var renameDict = new Dictionary <State, State>();

            var buffer = new List <State> {
                InitialState
            };

            var n = 1;

            while (buffer.Any())
            {
                var currentNode = buffer[0];

                var nextStops = Transitions.Where(tr => Equals(tr.StartState, currentNode) && !buffer.Contains(tr.EndState) && !renameDict.Keys.Contains(tr.EndState)).Select(tr => tr.EndState).Distinct(new StatesComparer()).ToList();

                if (nextStops.Any())
                {
                    buffer.AddRange(nextStops);
                }

                buffer.Remove(currentNode);
                renameDict.Add(currentNode, new State($"{startsWith}{n}", currentNode.IsFinal));
                n++;
            }

            var renamedMachine = new MachineDetermined();

            renamedMachine.AddStateRange(renameDict.Values);
            renamedMachine.AddTransitionRange(Transitions.Select(transition => new Transition(renameDict[transition.StartState], transition.Token, renameDict[transition.EndState])));
            renamedMachine.Init(renameDict[InitialState].Id);

            return(renamedMachine);
        }
        private static void DrawMaterialPropertySelector(Transitions sel, SerializedProperty transitionProp)
        {
            var matPropTrans = (sel.TransitionStates as MaterialPropertyTransition);

            if (matPropTrans == null)
            {
                return;
            }

            var img = (matPropTrans.Target as BetterImage);

            if (img == null)
            {
                return;
            }

            var options = img.MaterialProperties.FloatProperties.Select(o => o.Name).ToArray();

            var sp           = transitionProp.FindPropertyRelative("propertyIndex");
            int cur          = sp.intValue;
            int matPropIndex = EditorGUILayout.Popup("Affected Property", cur, options);

            sp.intValue = matPropIndex;
        }
Exemple #6
0
        private Event GenerateNextEvent(Token tk)
        {
            Event retVal;
            var   rnd = new Random();

            //To continue, or not to continue
            if (rnd.Next(1, 3) < 1 || tk.Location.Name == "p6")
            {
                return(null);
            }

            //The place were at
            var pl = Places.FirstOrDefault(p => p.IsEqual(tk.Location));

            Places.FirstOrDefault(p => p.IsEqual(tk.Location)).Capacity--;

            //Getting the connectors out of the place
            var conns = Connectors.Where(c => c.Pla.IsEqual(pl) && c.Direction == ConnectorDirection.PlTr);
            //Drafting the connector to select
            var firstConn = conns.ElementAt(rnd.Next(0, conns.Count() - 1));
            var tr        = Transitions.Single(t => t.IsEqual(firstConn.Trans));
            //Getting the connector leaving from the transition (should be single)
            var secoConn = Connectors.Single(c => c.Trans.IsEqual(tr) && c.Direction == ConnectorDirection.TrPl);

            //Increasing the capacity of the target place, and updating the location of the token
            tk.Location = Places.Single(p => p.IsEqual(secoConn.Pla));
            Places.Single(p => p.IsEqual(secoConn.Pla)).Capacity++;

            //Sending the updated data to the DB
            DbConn.Pn_UpdateToken(tk);
            DbConn.Pn_UpdateLocation(Places.Single(p => p.IsEqual(secoConn.Pla)));

            retVal = new Event(firstConn, secoConn, tk);

            return(retVal);
        }
        /// <param name="tNet">Petri net of the trace</param>
        /// <param name="pNet">Petri net of the model</param>
        /// <param name="traceMoveCost">Trace move cost</param>
        /// <param name="modelMoveCost">Model move cost</param>
        public SynchronousProductNet(IPetriNet tNet, IPetriNet pNet, int traceMoveCost = 1, int modelMoveCost = 1)
        {
            StartPlaces.Add(tNet.StartPlace);
            StartPlaces.Add(pNet.StartPlace);
            EndPlaces.Add(tNet.EndPlace);
            EndPlaces.Add(pNet.EndPlace);
            Places.AddRange(tNet.Places.Union(pNet.Places));

            PlacesToTransitions = Places.ToDictionary(p => p, p => new List <int>());

            InitTransitionsFromPNet(tNet, traceMoveCost, false);
            InitTransitionsFromPNet(pNet, modelMoveCost, true);

            //Add transitions for synchronous move as cost 0 + addition to make all costs positive
            foreach (var t1 in tNet.Transitions)
            {
                foreach (var t2 in pNet.Transitions)
                {
                    if (!t1.Activity.Equals(t2.Activity))
                    {
                        continue;
                    }
                    var transition = new Transition($"({t1.Id},{t2.Id})", t1.Activity);
                    transition.InputPlaces.AddRange(t1.InputPlaces.Union(t2.InputPlaces));
                    transition.OutputPlaces.AddRange(t1.OutputPlaces.Union(t2.OutputPlaces));
                    var syncTransition = new STransition(transition, 0);

                    foreach (var place in transition.InputPlaces)
                    {
                        PlacesToTransitions[place].Add(Transitions.Count);
                    }

                    Transitions.Add(syncTransition);
                }
            }
        }
        /// <summary>
        /// Remove a given node. A node can be a place or a transition.
        /// Version 2: Now also removes the connections in the nodes before and after.
        /// </summary>
        /// <param name="nodeToRemove"></param>
        /// <author>Roman Bauer, Jannik Arndt</author>
        public void RemoveNodeAndConnections(Node nodeToRemove)
        {
            if (nodeToRemove.GetType() == typeof(Place))
            {
                Place placeToRemove = nodeToRemove as Place;
                if (placeToRemove != null)
                {
                    foreach (Transition transition in placeToRemove.IncomingTransitions)
                    {
                        transition.OutgoingPlaces.Remove(placeToRemove);
                    }
                    foreach (Transition transition in placeToRemove.OutgoingTransitions)
                    {
                        transition.IncomingPlaces.Remove(placeToRemove);
                    }
                    Places.Remove(placeToRemove);
                }
            }

            if (nodeToRemove.GetType() == typeof(Transition))
            {
                Transition transitionToRemove = nodeToRemove as Transition;
                if (transitionToRemove != null)
                {
                    foreach (Place place in transitionToRemove.IncomingPlaces)
                    {
                        place.OutgoingTransitions.Remove(transitionToRemove);
                    }
                    foreach (Place place in transitionToRemove.OutgoingPlaces)
                    {
                        place.IncomingTransitions.Remove(transitionToRemove);
                    }
                    Transitions.Remove(transitionToRemove);
                }
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        transitions = Transitions.SharedComponent;
        transitions.FadeIn();

        if (!GameManager.invertYAxis)
        {
            flipYAxisText.text = "no";
        }

        audioSource = GetComponent <AudioSource>();

        ////Set Preview to upper left corner
        //var screenRes = Screen.currentResolution;
        //screenX = (float) screenRes.width;
        //screenY = (float) screenRes.height;

        //screenPreview.rect = new Rect(
        //    screenX * previewXPercentage,
        //    screenY * previewYPercentage,
        //    screenX * previewWidthPercentage,
        //    screenY * previewHeightPercentage
        //);
    }
Exemple #10
0
        IEnumerator TransitionScene(Scene scene, Transitions transition)
        {
            TweenManager.stopAllTweens();
            yield return(Coroutine.waitForSeconds(0.4f));

            switch (transition)
            {
            case Transitions.fade:
                Core.startSceneTransition(new FadeTransition(() => scene));
                break;

            case Transitions.cross:
                Core.startSceneTransition(new CrossFadeTransition(() => scene));
                break;

            case Transitions.squares:
                Core.startSceneTransition(new SquaresTransition(() => scene));
                break;

            default:
                Core.startSceneTransition(new FadeTransition(() => scene));
                break;
            }
        }
        private void TransformToStar(int start, int currState, FSM fsm, Set <int> visited)
        {
            if (visited.Contains(currState))
            {
                return;
            }
            else
            {
                visited.Add(currState);
            }

            Transitions currTrans = null;

            fsm.Trans.TryGetValue(currState, out currTrans);
            if (currTrans == null || currTrans.Count == 0)
            {
                return;
            }

            this.TransformToStar(
                currTrans.nameTransitions, start, currState, fsm, visited);
            this.TransformToStar(
                currTrans.wildCardTransitions, start, currState, fsm, visited);
        }
Exemple #12
0
        /// <summary>
        /// Creates a new finite automata with the given parameters.
        /// </summary>
        /// <param name="alphabet">The alphabet of the new automata.</param>
        /// <param name="states">The list of states of the new automata.</param>
        /// <param name="startState">The start state of the new automata.</param>
        /// <param name="transitions">The list of transitions of the new automata.</param>
        /// <param name="acceptingStates">The list of accepting transitions of the new automata.</param>
        public FiniteAutomata(IAlphabet alphabet, IEnumerable <IState> states, IState startState, IEnumerable <IStateTransition> transitions, IEnumerable <IState> acceptingStates)
        {
            if (states == null)
            {
                throw new ArgumentNullException(nameof(states), "The state list can not be null!");
            }

            if (startState == null)
            {
                throw new ArgumentNullException(nameof(startState), "The start state can not be null!");
            }

            if (transitions == null)
            {
                throw new ArgumentNullException(nameof(transitions), "The transition list can not be null!");
            }

            if (acceptingStates == null)
            {
                throw new ArgumentNullException(nameof(acceptingStates), "The accepting state list can not be null!");
            }

            Alphabet = alphabet ?? throw new ArgumentNullException(nameof(alphabet), "The alphabet can not be null!");

            startState.IsStartState = true;

            States.UnionWith(states);
            States.Add(startState);

            foreach (var state in acceptingStates)
            {
                state.IsAcceptState = true;
            }

            Transitions.UnionWith(transitions);
        }
Exemple #13
0
        public override void UpdateTransitions(Dictionary <PetrinetTransition, bool> visualize, Dictionary <PetrinetTransition, bool> readyToFire)
        {
            base.UpdateTransitions(visualize, readyToFire);

            var transitionsReady = Transitions.Where(r => r.GetConditionsFulfilled().All(v => v.Value));
            var firstReady       = transitionsReady.FirstOrDefault();

            if (firstReady == null)
            {
                return;
            }

            Colorize(firstReady, OutsideRenderer);

            //var firstPlaceOut = firstReady.Out.FirstOrDefault(i => i.Type == PetrinetCondition.ConditionType.Place);
            //if (firstPlaceOut != null)
            //{
            //    var houseLinker = firstPlaceOut.GetComponent<HouseLinker>();
            //    if (houseLinker != null)
            //    {
            //        houseLinker.ColorizeThis(MarkerRenderer);
            //    }
            //}
        }
 public void AddTransition(Transition <T> t)
 {
     Transitions.Add(t);
     States.Add(t.FromState);
     States.Add(t.ToState);
 }
Exemple #15
0
 private bool CustomEquals(WorkflowStep other)
 {
     return(Transitions.EqualsDictionary(other.Transitions));
 }
Exemple #16
0
 private void AddConnector(ViewModelConnector connector)
 {
     Transitions.Add(connector);
 }
 /// <summary>
 /// Short-hand method for adding a state transition.
 /// </summary>
 /// <param name="fromState">The previous visual state.</param>
 /// <param name="toState">The new visual state.</param>
 /// <param name="duration">Duration of the animation (in milliseconds).</param>
 public void AddTransition(TState fromState, TState toState, int duration)
 {
     Transitions.Add(new BufferedPaintTransition <TState>(fromState, toState, duration));
 }
Exemple #18
0
 public int TransitionIndex(string name)
 {
     return(Transitions.Where(pair => pair.Value == name).Select(valuePair => valuePair.Key).First());
 }
 private void PushCore(Transition transition)
 {
     Transitions.Add(transition);
 }
 void RunningToPause()
 {
     if(Input.GetKeyDown(KeyCode.Escape))
     {
         _fsm.Transition(GameStates.e_running, GameStates.e_pause);
         GUI.Label(new Rect(10,10,100,20),"Paused");
         _transitions = null;
         _transitions += checkState;
         _transitions();
     }
 }
 public Posture(Transitions state)
 {
     SetState(state);
 }
 public void SetState(Transitions state)
 {
     BaseState = State.Transitioning;
     TransitionState = state;
 }
 public uc_StateChangeInfo(
     States      p1,
     Transitions p2,
     NvtActions  p3)
 {
     //prntSome.printSome("uc_StateChangeInfo");
     this.State      = p1;
     this.Transition = p2;
     this.NextAction = p3;
 }
            public System.Boolean GetStateChangeAction(
                States      State,
                Transitions Transition,
                ref NvtActions  NextAction)
            {
                //prntSome.printSome("GetStateChangeAction");
                uc_StateChangeInfo Element;

                for (System.Int32 i = 0; i < Elements.Length; i++)
                {
                    Element = Elements[i];

                    if (State      == Element.State &&
                        Transition == Element.Transition)
                    {
                        NextAction = Element.NextAction;
                        return true;
                    }
                }

                return false;
            }
 protected override void EmitHandlerInvocation(Transitions.Event e)
 {
 }
 void Start()
 {
     _transitions += checkState; //adds the checkState function to the Delgate of _transition
     StartCoroutine("Transitioning"); //starts a couroutine
 }
 void PauseToExit()
 {
     if(Input.GetKeyDown(KeyCode.Q))
     {
         _fsm.Transition(GameStates.e_pause, GameStates.e_exit);
         _transitions = null;
         _transitions += checkState;
         _transitions();
     }
 }
 // Метод добавления функции перехода к следующему состоянию
 public void AddTransition(char a, State s)
 {
     Transitions.Add(a, s);
 }
 void PauseToRunning()
 {
     if(Input.GetKeyDown(KeyCode.E))
     {
         _fsm.Transition(GameStates.e_pause, GameStates.e_running);
         _transitions = null;
         _transitions += checkState;
         _transitions();
     }
 }
Exemple #30
0
 /// <summary>Has Add() to support cleaner initialization.</summary>
 /// <param name="stn"></param>
 /// <param name="entry"></param>
 /// <param name="exit"></param>
 /// <param name="transitions"></param>
 public void Add(S stn, SmFunc entry, SmFunc exit, Transitions <S, E> transitions) =>
 Add(new() { StateId = stn, EntryFunc = entry, ExitFunc = exit, Transitions = transitions });
 protected override void EmitSwitchCaseLabel(Transitions.Event e)
 {
 }
 public void LoadSceneWithTransition(Transitions transitionType, Scene scene)
 {
     Core.startCoroutine(TransitionScene(scene, transitionType));
 }
Exemple #33
0
 private Transition GetStartTransition()
 {
     return(Transitions.Where(t => t.From == StartId).FirstOrDefault());
 }
 public Transition Peek()
 {
     return(Transitions.LastOrDefault());
 }
Exemple #35
0
 private IEnumerable <Transition> GetTransitionsWithFrom(int id)
 {
     return(Transitions.Where(t => t.From == id));
 }
 private void Awake()
 {
     instance = this;
 }
Exemple #37
0
        private void SetStyles()
        {
            Transitions buttonPathTransitions = null;

            if (!ColorPicker.TransitionsDisabled)
            {
                buttonPathTransitions = new Transitions
                {
                    new SolidBrushTransition()
                    {
                        Property = Avalonia.Controls.Shapes.Path.StrokeProperty, Duration = new TimeSpan(0, 0, 0, 0, 100)
                    }
                };
            }

            Style ButtonBG = new Style(x => x.OfType <Canvas>().Class("ButtonBG"));

            ButtonBG.Setters.Add(new Setter(Canvas.BackgroundProperty, new SolidColorBrush(Color.FromArgb(0, 180, 180, 180))));
            ButtonBG.Setters.Add(new Setter(Canvas.CursorProperty, new Cursor(StandardCursorType.Hand)));
            if (!ColorPicker.TransitionsDisabled)
            {
                Transitions buttonBGTransitions = new Transitions
                {
                    new SolidBrushTransition()
                    {
                        Property = Canvas.BackgroundProperty, Duration = new TimeSpan(0, 0, 0, 0, 100)
                    }
                };

                ButtonBG.Setters.Add(new Setter(Canvas.TransitionsProperty, buttonBGTransitions));
            }
            this.Styles.Add(ButtonBG);

            Style DeleteButtonPath = new Style(x => x.OfType <Canvas>().Class("DeleteButton").Child().OfType <Avalonia.Controls.Shapes.Path>());

            DeleteButtonPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.StrokeProperty, new SolidColorBrush(Color.FromArgb(255, 237, 28, 36))));
            if (!ColorPicker.TransitionsDisabled)
            {
                DeleteButtonPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.TransitionsProperty, buttonPathTransitions));
            }
            this.Styles.Add(DeleteButtonPath);

            Style SaveButtonPath = new Style(x => x.OfType <Canvas>().Class("SaveButton").Child().OfType <Avalonia.Controls.Shapes.Path>());

            SaveButtonPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.FillProperty, new SolidColorBrush(Color.FromArgb(255, 86, 180, 233))));
            if (!ColorPicker.TransitionsDisabled)
            {
                SaveButtonPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.TransitionsProperty, buttonPathTransitions));
            }
            this.Styles.Add(SaveButtonPath);

            Style AddButtonPath = new Style(x => x.OfType <Canvas>().Class("AddButton").Child().OfType <Avalonia.Controls.Shapes.Path>());

            AddButtonPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.StrokeProperty, new SolidColorBrush(Color.FromArgb(255, 34, 177, 76))));
            if (!ColorPicker.TransitionsDisabled)
            {
                AddButtonPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.TransitionsProperty, buttonPathTransitions));
            }
            this.Styles.Add(AddButtonPath);

            Style ButtonBGOver = new Style(x => x.OfType <Canvas>().Class("ButtonBG").Class(":pointerover"));

            ButtonBGOver.Setters.Add(new Setter(Canvas.BackgroundProperty, new SolidColorBrush(Color.FromArgb(255, 180, 180, 180))));
            this.Styles.Add(ButtonBGOver);

            Style ButtonBGOverPath = new Style(x => x.OfType <Canvas>().Class("ButtonBG").Class(":pointerover").Child().OfType <Avalonia.Controls.Shapes.Path>());

            ButtonBGOverPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.StrokeProperty, Application.Current.FindResource("ThemeBackgroundBrush")));
            ButtonBGOverPath.Setters.Add(new Setter(Avalonia.Controls.Shapes.Path.FillProperty, Application.Current.FindResource("ThemeBackgroundBrush")));
            this.Styles.Add(ButtonBGOverPath);

            Style ButtonBGPressed = new Style(x => x.OfType <Canvas>().Class("ButtonBG").Class("pressed"));

            ButtonBGPressed.Setters.Add(new Setter(Canvas.BackgroundProperty, new SolidColorBrush(Color.FromArgb(255, 128, 128, 128))));
            this.Styles.Add(ButtonBGPressed);
        }
        void Control_Paint(object sender, PaintEventArgs e)
        {
            if (BufferedPaintSupported && Enabled)
            {
                bool stateChanged = !Object.Equals(_currentState, _newState);

                IntPtr hdc = e.Graphics.GetHdc();
                if (hdc != IntPtr.Zero)
                {
                    // see if this paint was generated by a soft-fade animation
                    if (!Interop.BufferedPaintRenderAnimation(Control.Handle, hdc))
                    {
                        Interop.BP_ANIMATIONPARAMS animParams = new Interop.BP_ANIMATIONPARAMS();
                        animParams.cbSize = Marshal.SizeOf(animParams);
                        animParams.style  = Interop.BP_ANIMATIONSTYLE.BPAS_LINEAR;

                        // get appropriate animation time depending on state transition (or 0 if unchanged)
                        animParams.dwDuration = 0;
                        if (stateChanged)
                        {
                            BufferedPaintTransition <TState> transition = Transitions.Where(x => Object.Equals(x.FromState, _currentState) && Object.Equals(x.ToState, _newState)).SingleOrDefault();
                            animParams.dwDuration = (transition != null) ? transition.Duration : DefaultDuration;
                        }

                        Rectangle rc = Control.ClientRectangle;
                        IntPtr    hdcFrom, hdcTo;
                        IntPtr    hbpAnimation = Interop.BeginBufferedAnimation(Control.Handle, hdc, ref rc, Interop.BP_BUFFERFORMAT.BPBF_COMPATIBLEBITMAP, IntPtr.Zero, ref animParams, out hdcFrom, out hdcTo);
                        if (hbpAnimation != IntPtr.Zero)
                        {
                            if (hdcFrom != IntPtr.Zero)
                            {
                                using (Graphics g = Graphics.FromHdc(hdcFrom)) {
                                    OnPaintVisualState(new BufferedPaintEventArgs <TState>(_currentState, g));
                                }
                            }
                            if (hdcTo != IntPtr.Zero)
                            {
                                using (Graphics g = Graphics.FromHdc(hdcTo)) {
                                    OnPaintVisualState(new BufferedPaintEventArgs <TState>(_newState, g));
                                }
                            }

                            _currentState = _newState;
                            Interop.EndBufferedAnimation(hbpAnimation, true);
                        }
                        else
                        {
                            OnPaintVisualState(new BufferedPaintEventArgs <TState>(_currentState, e.Graphics));
                        }
                    }

                    e.Graphics.ReleaseHdc(hdc);
                }
            }
            else
            {
                // buffered painting not supported, just paint using the current state
                _currentState = _newState;
                OnPaintVisualState(new BufferedPaintEventArgs <TState>(_currentState, e.Graphics));
            }
        }
                public readonly Transitions Transition; // the next state we are going to 

                public uc_StateChangeInfo(
                    States p1,
                    Transitions p2,
                    Actions p3)
                {
                    this.State = p1;
                    this.Transition = p2;
                    this.NextAction = p3;
                }
Exemple #40
0
 private void DeleteConnector(ViewModelConnector connector)
 {
     Transitions.Remove(connector);
 }
Exemple #41
0
    void CheckStates()
    {
        if (_transitions != null)
            _transitions = null;

        switch(_fsm.state)
        {
            case CombatStates.eInit:
                {
                    ChangeState(CombatStates.eSearch);
                    break;
                }
            case CombatStates.eSearch:
                {
                    if(MaxFighters())
                    {
                        ChangeState(CombatStates.eCheckActions);
                    }
                    break;
                }

            case CombatStates.eCheckActions:
                {
                    /*
                        loops through all the fighters in the list
                        if they have all selected an action we will
                        change state
                    */
                    if (ActionsSelected())
                    {
                        ChangeState(CombatStates.ePerformActions);
                    }
                    break;
                }

            case CombatStates.ePerformActions:
                {
                    iUnitsReady = 0;
                    ChangeState(CombatStates.eCheckConditions);
                    break;
                }

            case CombatStates.eCheckConditions:
                {
                    if(WinCondition())
                        ChangeState(CombatStates.eExit);

                    else
                        ChangeState(CombatStates.eCheckActions);

                    break;
                }

            case CombatStates.eExit:
                {
                    LeaveCombat();
                    if(Fighters == null)
                        ChangeState(CombatStates.eSearch);
                    break;
                }
            default:
                break;
        }
        if(_transitions != null)
            _transitions();
    }
Exemple #42
0
 private int CustomHashCode()
 {
     return(Transitions.DictionaryHashCode());
 }
Exemple #43
0
 // Use this for initialization
 void Start()
 {
     _transitions += CheckState;
 }
 public List <Transition <T> > GetToStates(T state, char symbol)
 {
     return(Transitions.Where(e => e.Symbol == symbol).Where(e => e.FromState.Equals(state)).ToList());
 }
 void InitToRunning()
 {
     _fsm.Transition(GameStates.e_intit, GameStates.e_running);
     _transitions = null;
     _transitions += checkState;
     _transitions();
 }
Exemple #46
0
 private IEnumerable <Transition> GetTransitionsWithTo(int id)
 {
     return(Transitions.Where(t => t.To == id));
 }
 private void switchTransition()
 {
     switch (transition) {
     case Transitions.A:
         if ( Input.GetMouseButtonDown(0) ) {
             transition = Transitions.AM0;
         } else if ( Input.GetKeyDown("a") ) {
             transition = Transitions.NULL;
         }
         break;
     case Transitions.AM0:
     case Transitions.M1:
         transition = Transitions.NULL;
         break;
     case Transitions.NULL:
         if ( Input.GetKeyDown("a") ) {
             transition = Transitions.A;
         } else if ( Input.GetMouseButtonDown(1) ) {
             transition = Transitions.M1;
         }
         break;
     }
 }
Exemple #48
0
        public DFA <IEnumerable <T>, U> toDFA()
        {
            DFA <IEnumerable <T>, U> result = new DFA <IEnumerable <T>, U>();
            HashSet <StateSet <T> >  curr   = new HashSet <StateSet <T> >();

            // Add start state
            StateSet <T> start = new StateSet <T>();

            foreach (T startState in StartStates)
            {
                start.UnionWith(epsilonClosure(startState));
            }
            curr.Add(start);
            result.addStartState(start);

            // Add trap state
            StateSet <T> trap = new StateSet <T>();

            foreach (U terminal in Alphabet)
            {
                result.addTransition(terminal, trap, trap);
            }

            // Add transitions
            bool done = false;

            while (!done)
            {
                bool addedNew = false;
                HashSet <StateSet <T> > next = new HashSet <StateSet <T> >();
                // For each current state in set of current states.
                foreach (StateSet <T> currState in curr)
                {
                    // For each terminal in the alphabet.
                    foreach (U terminal in Alphabet)
                    {
                        // nextState will become the actual dfa to state.
                        StateSet <T> nextState = new StateSet <T>();
                        // For each ndfa state of which the dfa state is made.
                        foreach (T subState in currState)
                        {
                            // Get the epsilon closure of the sub state.
                            HashSet <T> preClosure = epsilonClosure(subState);
                            // For each state in the epsilon closure.
                            foreach (T preClosureState in preClosure)
                            {
                                // Check if exists.
                                if (!Transitions.ContainsKey(preClosureState) || !Transitions[preClosureState].ContainsKey(terminal))
                                {
                                    continue;
                                }
                                // Get all the to states for this terminal.
                                HashSet <T> follow = Transitions[preClosureState][terminal];
                                // Accumulate the epsilon closure of each followed state.
                                foreach (T followedState in follow)
                                {
                                    HashSet <T> postClosure = epsilonClosure(followedState);
                                    nextState.UnionWith(postClosure);
                                }
                            }
                        }

                        if (nextState.Count() > 0)
                        {
                            next.Add(nextState);
                            // Add transition.
                            if (result.addTransition(terminal, currState, nextState))
                            {
                                addedNew = true;
                            }
                            // Add end state
                            if (EndStates.Intersect(nextState).Count() > 0)
                            {
                                result.addEndState(nextState);
                            }
                        }
                        else
                        {
                            /*
                             * . . . . . . . . . . . . . . . .   ____________
                             * . . . . . . . . . . . . . . . . / It’s a trap! \
                             * . . . . . . . . . . . . . . . . \ _____________/
                             * __...------------._
                             * ,-'                   `-.
                             * ,-'                         `.
                             * ,'                            ,-`.
                             * ;                              `-' `.
                             * ;                                 .-. \
                             * ;                           .-.    `-'  \
                             * ;                            `-'          \
                             * ;                                          `.
                             * ;                                           :
                             * ;                                            |
                             * ;                                             ;
                             * ;                            ___              ;
                             * ;                        ,-;-','.`.__          |
                             * _..;                      ,-' ;`,'.`,'.--`.        |
                             * ///;           ,-'   `. ,-'   ;` ;`,','_.--=:      /
                             |'':          ,'        :     ;` ;,;,,-'_.-._`.   ,'
                             * '  :         ;_.-.      `.    :' ;;;'.ee.    \|  /
                             \.'    _..-'/8o. `.     :    :! ' ':8888)   || /
                             ||`-''    \\88o\ :     :    :! :  :`""'    ;;/
                             ||         \"88o\;     `.    \ `. `.      ;,'
                             ||/)   ___    `."'/(--.._ `.    `.`.  `-..-' ;--.
                             \(.="""""==.. `'-'     `.|      `-`-..__.-' `. `.
                             |          `"==.__      )                    )  ;
                             |   ||           `"=== '                   .'  .'
                             | /\,,||||  | |           \                .'   .'
                             | |||'|' |'|'           \|             .'   _.' \
                             | |\' |  |           || ||           .'    .'    \
                             | ' | \ ' |'  .   ``-- `| ||         .'    .'       \
                             | '  |  ' |  .    ``-.._ |  ;    .'    .'          `.
                             | _.--,;`.       .  --  ...._,'   .'    .'              `.__
                             | ,'  ,';   `.     .   --..__..--'.'    .'                __/_\
                             | ,'   ; ;     |    .   --..__.._.'     .'                ,'     `.
                             | /    ; :     ;     .    -.. _.'     _.'                 /         `
                             | /     :  `-._ |    .    _.--'     _.'                   |
                             | /       `.    `--....--''       _.'                      |
                             | `._              _..-'                         |
                             | `-..____...-''                              |
                             |
                             |
                             */
                            result.addTransition(terminal, currState, trap);
                        }
                    }
                }
                curr = next;
                done = !addedNew;
            }

            return(result);
        }
    void CheckStates()
    {
        if (_transitions != null)
            _transitions = null;

        switch(_fsm.state)
        {
            case CombatStates.eInit:
                {
                    ChangeState(CombatStates.eSearch);
                    break;
                }
            case CombatStates.eSearch:
                {
                    if(MaxFighters())
                    {
                        ChangeState(CombatStates.eCheckActions);
                    }
                    break;
                }

            case CombatStates.eCheckActions:
                {
                    /*
                        loops through all the fighters in the list
                        if they have all selected an action we will
                        change state
                    */
                    Publish("Combat_Manager_Select_Action");
                    if (ActionsSelected())
                    {
                        ChangeState(CombatStates.ePerformActions);
                    }
                    break;
                }

            case CombatStates.ePerformActions:
                {
                    iUnitsReady = 0;
                    DoAttacks();
                    break;
                }

            case CombatStates.eCheckConditions:
                {
                    /*
                        Checks the see if the wincondition has been met and if it has
                        Combat is ended
                        If it hasn't we start the combat phase all over again at the
                        select action state
                    */
                    if(WinCondition())
                    {
                        Publish("_Combat_Manager_Leave_Combat");
                        ChangeState(CombatStates.eExit);
                    }

                    else
                        ChangeState(CombatStates.eCheckActions);

                    break;
                }

            case CombatStates.eExit:
                {
                    LeaveCombat();
                    if(Fighters == null)
                        ChangeState(CombatStates.eSearch);
                    break;
                }
            default:
                break;
        }
        if(_transitions != null)
            _transitions();
    }
                public Boolean GetStateChangeAction(
                    States State,
                    Transitions Transition,
                    ref Actions NextAction)
                {
                    uc_StateChangeInfo Element;

                    for (Int32 i = 0; i < this.Elements.Length; i++)
                    {
                        Element = this.Elements[i];

                        if (State == Element.State &&
                            Transition == Element.Transition)
                        {
                            NextAction = Element.NextAction;
                            return true;
                        }
                    }

                    return false;
                }
 void Start()
 {
     Subscribe("_Dead", FighterKilled);
     _transitions += CheckStates;
     StartCoroutine("Transitioning");
 }
Exemple #52
0
 void ChangeState(CombatStates To)
 {
     _fsm.Transition(_fsm.state, To);
     if (_transitions != null)
     {
         _transitions = null;
     }
     _transitions += CheckStates;
 }
 protected override void EmitSwitchCaseLabel(Transitions.Event e)
 {
     Writer.AppendLine("case \"" + e.Name + "\":");
 }
Exemple #54
0
 void Start()
 {
     _transitions += CheckStates;
     StartCoroutine("Transitioning");
 }
 protected override void EmitHandlerInvocation(Transitions.Event e)
 {
     Writer.AppendLine("this." + e.Name + "_Handler();");
     Writer.AppendLine("break;");
 }