Example #1
0
        public StateMachine.RuleStateEventArgs GoToState()
        {
            if (strip == null)
            {
                return(InitStrip());
            }
            bool init = false;

            strip.CheckBounds(ref SelectedCell);
            try
            {
                if (History.Count == 0 || execState == null)
                {
                    //init q0 state
                    InitState();
                    init = true;
                }
                else
                {
                    //get next
                    execState = Table.Where(x =>
                                            x.Q == execState.ReferenceState.NextQ &&
                                            x.Marker == strip[SelectedCell]).First();
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Unknown letter under carret");
                return(null);
            } //q0 stop
            if (execState != null &&
                execState.Q == 0 &&
                !init)
            {
                return
                    new StateMachine.RuleStateEventArgs(
                    new FinishedState(execState))
                    {
                        State = StateMachine.RuleStateEventArgs.OnState.Finished |
                                StateMachine.RuleStateEventArgs.OnState.NewState
                    }
            }
            ;

            //setting history state for current exec
            var hi = execState.ReferenceState.Clone();

            hi.SetMarker = strip[SelectedCell];
            execState.SetPrevState(hi);
            //changing cell
            strip[SelectedCell] = execState.ReferenceState.SetMarker;
            //moving marker
            execState.ReferenceState.GetNextSelected(ref SelectedCell);

            //adding to history
            History.Add(execState);
            return(new StateMachine.RuleStateEventArgs(execState)
            {
                State = StateMachine.RuleStateEventArgs.OnState.NewState
            });
        }