public override void Execute(IList <Token> tokens, ref int i)
 {
     if (tokens[i].TokenType == TokenType.Identifier)
     {
     }
     StateStack.Push(new ConstructionBodyState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, Method));
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            Terminal.Open();
            Terminal.Set(string.Format("window.title='{0}'", "SharpSnake"));
            Terminal.Refresh();

            var consoleScreen = new ConsoleScreen(36, 28);
            var context       = new StateContext(consoleScreen, new Settings());
            var stateStack    = new StateStack(context);

            stateStack.RegisterState <MenuState>(StateId.Menu);
            stateStack.RegisterState <OptionsState>(StateId.Options);
            stateStack.RegisterState <PlayState>(StateId.Play);
            stateStack.RegisterState <GameOverState>(StateId.GameOver);
            stateStack.RegisterState <PauseState>(StateId.Pause);

            // Initial state
            stateStack.PushState(StateId.Menu);

            while (!stateStack.Empty)
            {
                stateStack.HandleInput();
                stateStack.Update();

                consoleScreen.Clear();
                stateStack.Draw();
                consoleScreen.Display();

                System.Threading.Thread.Sleep(16);
            }

            Terminal.Close();
        }
Beispiel #3
0
        public ParsingObject ToStack(State newState, bool important = true)
        {
            logger.Debug($"Push {newState.ToString()}");
            if (important)
            {
                CurrentToken += '{' + TokenParameters.Count.ToString() + '}';
            }
            StateStack.Push(this);
            var newObject = new ParsingObject
            {
                State             = newState,
                Index             = Index,
                CurrentHtmlObject = new HtmlObject
                {
                    Attributes = new List <DataAtrModel>(),
                    Children   = new List <HtmlObject>(),
                    Parent     = CurrentHtmlObject,
                    Tag        = string.Empty
                },
                CurrentToken    = string.Empty,
                ParenthStack    = new Stack <char>(),
                RawHtml         = RawHtml,
                StateStack      = StateStack,
                TokenParameters = new List <ParsingObject>()
            };

            newObject._startIndex = Index;
            newObject._important  = important;
            return(newObject);
        }
Beispiel #4
0
        /// <summary>
        /// Find error recovery state.
        /// </summary>
        /// <returns>result.</returns>
        private bool FindErrorRecoveryState()
        {
            while (true)    // pop states until one found that accepts error token
            {
                if (FsaState.ParserTable != null &&
                    FsaState.ParserTable.ContainsKey(errorToken) &&
                    FsaState.ParserTable[errorToken] > 0) // shift
                {
                    return(true);
                }

                StateStack.Pop();
                ValueStack.Pop();
                LocationStack.Pop();

                if (StateStack.IsEmpty())
                {
                    return(false);
                }
                else
                {
                    FsaState = StateStack.TopElement();
                }
            }
        }
 public override void Execute(IList <Token> tokens, ref int i)
 {
     if (tokens[i].TokenType == TokenType.Modifier)
     {
         modifs.Add(tokens[i].Value);
         i++;
     }
     else if (tokens[i].Value == "func")
     {
         i++;
         StateStack.Push(new MethodState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, modifs.ToArray()));
         modifs.Clear();
     }
     else if (tokens[i].TokenType == TokenType.Type)
     {
         StateStack.Push(new FieldState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, modifs.ToArray()));
         modifs.Clear();
     }
     else if (tokens[i].TokenType == TokenType.End)
     {
         i++;
         StateStack.Pop();
         StateStack.Pop();
         ((TypeBuilder)TypeBuilder).CreateType();
     }
     else
     {
         ExceptionManager.ThrowCompiler(ErrorCode.UnexpectedToken, "", tokens[i].Line);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollapsingStateStack{T}"/> class.
 /// </summary>
 /// <param name="capacity">The initial capacity of the stack. This is the expected maximum stack depth.
 /// If the stack depth grows bigger, the stack automatically doubles its capacity internally.</param>
 public CollapsingStateStack(int capacity = _defaultCapacity)
 {
     // The _impStack keeps the actual top-of-stack values.
     _impStack = new StateStack <T>(capacity);
     // The _countStack keeps the number of "Push" operations that occurred between two Tos alterations
     _countStack = new StateStack <int>(capacity);
 }
        public MainScreen()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);

            Dictionary <string, IState> states = new Dictionary <string, IState>()
            {
                { "MainMenu", new MainMenuState() },
                { "Logo", new LogoState() }
            };

            _GameStack = new StateStack(this, ClientSize.Width, ClientSize.Height, states);
            _GameStack.Push("MainMenu");
            _GameStack.Push("Logo");

            _GameTimer          = new Timer();
            _GameTimer.Interval = 10;
            _GameTimer.Tick    += new EventHandler(_GameStack.Update);
            _GameTimer.Start();

            ResizeEnd += new EventHandler(_GameStack.Buffer);
            Load      += new EventHandler(_GameStack.Buffer);
            KeyDown   += new KeyEventHandler(_GameStack.Input);
            Paint     += new PaintEventHandler(_GameStack.Render);
        }
Beispiel #8
0
        /// <summary>
        /// Pop the current versioning state, returning the state to the one before it was pushed
        /// </summary>
        public void PopState()
        {
            var state = StateStack.Pop();

            this.Mode            = state.Mode;
            this.SpecificVersion = state.SpecificVersion;
        }
Beispiel #9
0
    public override void InitState(EntityStats receiver, EntityStats applier = null)
    {
        StateStack ss = receiver.GetStack(this);

        if (ss == null)
        {
            ss = new StateStack(this, stunDuration, 1);
            receiver.states.Add(ss);
        }
        else
        {
            ss.ResetTimer();
        }

        /* receiver.canMove = false;
         * SkillUser su = receiver.GetComponent<SkillUser>();
         * if(su){
         *  su.canCastSkills = false;
         * } */
        SkillUser su = receiver.GetComponent <SkillUser>();

        if (su)
        {
            su.canCastSkills = false;
        }
        receiver.stunned = true;
    }
Beispiel #10
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="createModel">Creates model that should be checked.</param>
        /// <param name="output">The callback that should be used to output messages.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        internal InvariantChecker(Func <RuntimeModel> createModel, Action <string> output, AnalysisConfiguration configuration)
        {
            Requires.NotNull(createModel, nameof(createModel));
            Requires.NotNull(output, nameof(output));

            _progressOnly = configuration.ProgressReportsOnly;
            _output       = output;
            _workers      = new Worker[configuration.CpuCount];

            var tasks  = new Task[configuration.CpuCount];
            var stacks = new StateStack[configuration.CpuCount];

            _loadBalancer = new LoadBalancer(stacks);

            for (var i = 0; i < configuration.CpuCount; ++i)
            {
                var index = i;
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    stacks[index]   = new StateStack(configuration.StackCapacity);
                    _workers[index] = new Worker(index, this, stacks[index], createModel, configuration.SuccessorCapacity);
                });
            }

            Task.WaitAll(tasks);

            _states = new StateStorage(_workers[0].StateVectorLayout, configuration.StateCapacity);

#if false
            Console.WriteLine(_workers[0].StateVectorLayout);
#endif
        }
Beispiel #11
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="createModel">Creates the model that should be checked.</param>
		/// <param name="output">The callback that should be used to output messages.</param>
		/// <param name="configuration">The analysis configuration that should be used.</param>
		internal ModelTraverser(Func<AnalysisModel> createModel, Action<string> output, AnalysisConfiguration configuration)
		{
			Requires.NotNull(createModel, nameof(createModel));
			Requires.NotNull(output, nameof(output));
			TransitionCollection.ValidateTransitionSizes();

			var tasks = new Task[configuration.CpuCount];
			var stacks = new StateStack[configuration.CpuCount];

			_loadBalancer = new LoadBalancer(stacks);
			Context = new TraversalContext(_loadBalancer, configuration, output);
			_workers = new Worker[configuration.CpuCount];

			for (var i = 0; i < configuration.CpuCount; ++i)
			{
				var index = i;
				tasks[i] = Task.Factory.StartNew(() =>
				{
					stacks[index] = new StateStack(configuration.StackCapacity);
					_workers[index] = new Worker(index, Context, stacks[index], createModel());
				});
			}

			Task.WaitAll(tasks);

			_states = new StateStorage(_workers[0].Model.StateVectorSize, configuration.StateCapacity);
			Context.States = _states;
		}
Beispiel #12
0
        public void OnObjectStart(string name)
        {
            var state = new KVPartialState();

            state.Key = name;
            StateStack.Push(state);
        }
Beispiel #13
0
        /// <summary>
        /// Run logic for this state - including input
        /// </summary>
        /// <param name="GameTime">Snapshot of timing</param>
        public override void Update(GameTime GameTime)
        {
            // Get the current state, get the last state, and any new buttons are acted upon
            var currentState = Keyboard.GetState();

            foreach (var i in currentState.GetPressedKeys())
            {
                if (LastState.IsKeyUp(i))
                {
                    StateStack.Clear();
                }
            }


            // Get touch state
            var touchState = TouchPanel.GetState();

            foreach (var touch in touchState)
            {
                if (touch.State == TouchLocationState.Pressed)
                {
                    StateStack.Clear();
                }
            }

            LastState = currentState;
        }
Beispiel #14
0
    public override void InitState(EntityStats receiver, EntityStats applier = null)
    {
        if (amount <= 0 || amount > maxAmount)
        {
            return;
        }
        StateStack ss = new StateStack(this, -1, -1, 1, applier);

        receiver.states.Add(ss);
        addedMod = new StatModifier(values[amount - 1], targetModType, this);
        if (targetType == StatType.STRENGTH)
        {
            receiver.strength.AddModifier(addedMod);
        }
        if (targetType == StatType.MIND)
        {
            receiver.mind.AddModifier(addedMod);
        }
        if (targetType == StatType.CONSTITUTION)
        {
            receiver.constitution.AddModifier(addedMod);
        }
        if (targetType == StatType.SPIRIT)
        {
            receiver.spirit.AddModifier(addedMod);
        }
    }
        /// <summary>
        /// Run logic for this state - including input
        /// </summary>
        /// <param name="GameTime">Snapshot of timing</param>
        public override void Update(GameTime GameTime)
        {
            // Get the current state, get the last state, and any new buttons are acted upon
            var currentState = Keyboard.GetState();

            foreach (var i in currentState.GetPressedKeys())
            {
                if (LastState.IsKeyUp(i))
                {
                    KeyPressed(i);
                }
            }
            LastState = currentState;

            // Do turn, if player next move is set
            if (G.Player.NextMove != Player.Instruction.NOT_SET)
            {
                G.DoTurn();
            }

            if (G.GameOver)
            {
                StateStack.Add(new AtlasWarriors.LoseState(G));
            }
        }
Beispiel #16
0
        /// <summary>
        /// Shift.
        /// </summary>
        /// <param name="stateIndex">state index.</param>
        private void Shift(int stateIndex)
        {
            FsaState = states[stateIndex];

            ValueStack.Push(Scanner.yylval);
            StateStack.Push(FsaState);
            LocationStack.Push(Scanner.yylloc);

            if (recovering)
            {
                if (NextToken != errorToken)
                {
                    tokensSinceLastError++;
                }

                if (tokensSinceLastError > 5)
                {
                    recovering = false;
                }
            }

            if (NextToken != endOfFileToken)
            {
                NextToken = 0;
            }
        }
Beispiel #17
0
 public void OnAfterDeserialize()
 {
     for (int i = StateList.Count; i >= 0; i--)
     {
         StateStack.Push(StateList[i]);
     }
 }
Beispiel #18
0
 /// <summary>
 /// Resume state is used for when we want to go back to a state we previously suspended.
 /// </summary>
 public void ResumeState()
 {
     if (StateStack.Count != 0)
     {
         CurrentState.Exit();
         CurrentState = StateStack.Pop();
     }
 }
Beispiel #19
0
        public void OnObjectStart(string name)
        {
            var state = new KvPartialState {
                Key = name
            };

            StateStack.Push(state);
        }
Beispiel #20
0
        public void RemoveHeadState()
        {
            if (StateStack.Count < 1)
            {
                throw new Exception("There are no more states to remove");
            }

            StateStack.RemoveAt(0);
        }
        protected override void FinalizeState()
        {
            base.FinalizeState();

            var stateEntry         = StateStack.Peek();
            var originalStateEntry = originalBuilder.StateStack.Peek();

            Merge(from: stateEntry, into: originalStateEntry);
        }
        protected void RemoveInstanceCore <TInstance>(string extName)
        {
            var cell = StateStack.FirstOrDefault(p => p.InstanceType == typeof(TInstance) && p.ExtName == extName);

            if (cell != null)
            {
                StateStack.Remove(cell);
            }
        }
Beispiel #23
0
 public void ClearStates()
 {
     while (StateStack.Count != 0)
     {
         CurrentState.Exit();
         CurrentState = StateStack.Pop();
     }
     CurrentState.Exit();
 }
Beispiel #24
0
    // Use this for initialization
    void Start()
    {
        stateStack = GetComponent <StateStack>();

        //Add all possible states here
        stateStack.Add("Game", new GameState());

        //Push the first thingy on
        stateStack.Push("Game");
    }
Beispiel #25
0
 public void PushState()
 {
     StateStack.Add(
         new StreamState
     {
         Position = Position,
         Mode     = Mode
     }
         );
 }
Beispiel #26
0
 //TODO activate the current state when the stack is empty
 public void PopState()
 {
     if (StateStack.Count == 0)
     {
         throw new Exception("The state stack is empty. Cannot pop.");
     }
     StateStack.Peek().OnExit();
     StateStack.Peek().gameObject.SetActive(false);
     StateStack.Pop();
 }
Beispiel #27
0
 /// <summary>
 /// Push something onto the state Stack of the bot, this calls the Stop() of current State
 /// and the Start() of new State.
 /// </summary>
 /// <param name="botState">the state you want to change to</param>
 public void PushAction(BotState botState, [CallerMemberName] string functionName = "")
 {
     if (GetCurrentState() != botState)
     {
         AmeisenLogger.Instance.Log(LogLevel.VERBOSE, $"FSM Push [{botState}] called by: {functionName}", this);
         GetCurrentStateAction(GetCurrentState())?.StartExit.Invoke();
         StateStack.Push(botState);
         GetCurrentStateAction(GetCurrentState())?.StartAction.Invoke();
     }
 }
Beispiel #28
0
 /// <summary>
 /// Push a versioning state with a VersioningMode and a specific ItemVersion (making it active)
 /// </summary>
 /// <param name="mode">The VersioningMode to push</param>
 /// <param name="specificVersion">The SpecificVersion to push</param>
 public void PushState(VersioningMode mode, ItemVersion specificVersion)
 {
     StateStack.Push(new VersioningState {
         Mode = this.Mode, SpecificVersion = this.SpecificVersion
     });
     this.Mode = mode;
     if (specificVersion != null)
     {
         this.SpecificVersion = specificVersion;
     }
 }
Beispiel #29
0
        public ParsingObject PopAttributeValue()
        {
            logger.Debug($"PopAttributeValue {State}");
            var attribute = StateStack.Pop();
            var element   = attribute.StateStack.Pop();

            element.currentAttr.ValueTemplate = CurrentToken;
            attribute.Index = Index;
            attribute.StateStack.Push(element);
            return(attribute);
        }
        protected override void FinalizeState()
        {
            base.FinalizeState();

            var stateEntry         = StateStack.Peek();
            var originalStateEntry = originalBuilder.StateStack.Peek();

            foreach (var item in stateEntry.Items)
            {
                originalStateEntry.Items.Add(item);
            }
        }
Beispiel #31
0
 /// <summary>
 /// Pop the state Stack of the bot, calls the Start() of new State and the Stop() of current State.
 /// </summary>
 /// <param name="botState">the state you want to change to</param>
 public BotState PopAction(BotState botState, [CallerMemberName] string functionName = "")
 {
     if (GetCurrentState() == botState)
     {
         AmeisenLogger.Instance.Log(LogLevel.VERBOSE, $"FSM Pop called by: {functionName}", this);
         GetCurrentStateAction(GetCurrentState())?.StartExit.Invoke();
         BotState tmpState = StateStack.Pop();
         GetCurrentStateAction(GetCurrentState())?.StartAction.Invoke();
         return(tmpState);
     }
     return(GetCurrentState());
 }