Example #1
1
 public FSAString()
 {
     state = State.START;
     fsachar = new FSAChar('\"');
     raw = "";
     val = "";
 }
        /// <summary>
        /// A connection to our server, always listening asynchronously.
        /// </summary>
        /// <param name="socket">The Socket for the connection.</param>
        /// <param name="args">The SocketAsyncEventArgs for asyncronous recieves.</param>
        /// <param name="dataReceived">A callback invoked when data is recieved.</param>
        /// <param name="disconnectedCallback">A callback invoked on disconnection.</param>
        public ServerConnection(Socket socket, SocketAsyncEventArgs args, DataReceivedCallback dataReceived,
            DisconnectedCallback disconnectedCallback)
        {
            logger = new ElibLogging("data");
            this.AuthorizationType = Securtiy.AuthorizationType.Anonymous;
            lock (this)
            {
                var remotIP = socket.RemoteEndPoint as IPEndPoint;
                var localIP = socket.LocalEndPoint as IPEndPoint;
                State state = new State()
                {
                    socket = socket,
                    dataReceived = dataReceived,
                    disconnectedCallback = disconnectedCallback,
                    Device = new Device()
                    {
                        RemoteIP = remotIP.Address.ToString(),
                        LocalIP = localIP.Address.ToString()
                    }
                };

                eventArgs = args;
                eventArgs.Completed += ReceivedCompleted;
                eventArgs.UserToken = state;

                ListenForData(eventArgs);
            }
        }
Example #3
0
        private State AddTrapState(FiniteAutomata dfa)
        {
            var trapState = new State("trap") {Id = int.MaxValue};
            for (int i = 0; i <= Byte.MaxValue; i++)
            {
                trapState.AddTransitionTo(trapState, InputChar.For((byte) i));
            }

            var states = dfa.GetStates();
            foreach (var state in states)
            {
                bool[] usedTransitions = new bool[Byte.MaxValue + 1]; // All nulls
                foreach (var transition in state.Transitions)
                {
                    usedTransitions[transition.Key.Value] = true; // mark used symbol
                }

                for (int i = 0; i <= Byte.MaxValue; i++)
                {
                    if (!usedTransitions[i])
                    {
                        state.AddTransitionTo(trapState, InputChar.For((byte)i));
                    }
                }
            }

            return trapState;
        }
Example #4
0
 public void creditsButtonPresed()
 {
     cameraAnimator.SetTrigger("Credits");
     menuAnim.SetTrigger("Credits");
     creditsAnimator.SetTrigger("Credits");
     currentState = State.Credits;
 }
        /// <summary>
        /// Called when we should show something
        /// </summary>
        /// <param name="link"></param>
        public void ShowContent(string link)
        {
            // Make sure we are in the correct state
            lock(this)
            {
                if(m_state != State.Idle)
                {
                    return;
                }
                m_state = State.Opening;
            }

            // Create the content control
            m_contentControl = new FlipViewContentControl();

            // This isn't great, but for now mock a post
            Post post = new Post() { Url = link, Id = "quinn" };

            // Add the control to the UI
            ui_contentRoot.Children.Add(m_contentControl);

            // Set the post to begin loading
            m_contentControl.FlipPost = post;
            m_contentControl.IsVisible = true;

            // Show the panel
            ToggleShown(true);
        }
 public static TimeSpan GetDefaultStartTimeForState(State state)
 {
     return
         DefaultStartTimeForState.ContainsKey(state)
             ? DefaultStartTimeForState[state]
             : TimeSpan.Zero;
 }
        /// <summary>
        /// Loads the specified script.
        /// </summary>
        /// <param name="script">The script.</param>
        public virtual void Load(string script)
        {
            if (script != null)
            {
                int l = script.Length;
                char c;
                m_sb = new StringBuilder(100);
                m_state = State.None;
                m_isAllWhitespace = true;

                for (int i = 0; i < l; i++)
                {
                    c = script[i];

                    switch (m_state)
                    {
                        default:

                            if (c == '{')
                            {
                            }

                            if (m_isAllWhitespace && !IsEcmaScriptWhitespace(c))
                            {
                                m_isAllWhitespace = false;
                            }

                            m_sb.Append(c);
                            continue;
                    }
                }
            }
        }
Example #8
0
    public static void Main()
    {
        string passcode = Console.ReadLine();
        var initialState = new State(0, 0, passcode);
        int steps = 1;
        int longest = 0;
        var currentStates = new List<State>();
        var nextStates = new List<State>();
        var visited = new HashSet<string>();
        currentStates.Add(initialState);

        while (currentStates.Count > 0) {
          foreach (State state in currentStates) {
        foreach (State nextState in state.Adjacent) {
          if (nextState.IsDestination) {
            longest = Math.Max(longest, steps);
            continue;
          }

          if (!visited.Contains(nextState.code)) {
            nextStates.Add(nextState);
            visited.Add(nextState.code);
          }
        }
          }

          currentStates = nextStates;
          nextStates = new List<State>();
          steps++;
        }

        Console.WriteLine($"Longest path was {longest} steps");
    }
Example #9
0
    IEnumerator Attack()
    {
        currState = State.Attacking;
        pathFinder.enabled = false;
        skinMaterial.color = Color.red;

        Vector3 startPos = transform.position;
        Vector3 directionToTarget = (target.position - transform.position).normalized;
        Vector3 endPos =  target.position - directionToTarget * (myCollisionRadius); //new Vector3(target.position.x, 1, target.position.z);

        float percent = 0.0f;
        float attackSpeed = 3.0f;

        bool hasAppliedDamage = false;

        while(percent <= 1.0f)
        {
            percent += Time.deltaTime * attackSpeed;
            float interpolation = ((- percent * percent) + percent) * 4;
            transform.position = Vector3.Lerp(startPos, endPos, interpolation);

            if(percent >= .5f && !hasAppliedDamage)
            {
                hasAppliedDamage = true;
                livingEntity.TakeDamage(damage);
            }

            yield return null;
        }

        pathFinder.enabled = true;
        skinMaterial.color = originalColor;
        currState = State.Chasing;
    }
Example #10
0
        public StateTest()
        {
            this.stateMachineInformation = A.Fake<IStateMachineInformation<States, Events>>();
            this.extensionHost = A.Fake<IExtensionHost<States, Events>>();

            this.testee = new State<States, Events>(States.A, this.stateMachineInformation, this.extensionHost);
        }
Example #11
0
	// Update is called once per frame
	void Update () {

		//Debug.Log ("Active state: " + activeState);
		//Debug.Log ("Food location" + foodLocation);
		//Debug.Log ("Found pheromone?" + foundPheromone);
		//Debug.Log ("Ant perspective: " + transportingFood);
		
		// A switch statement to change between the three behavior states.
		switch (activeState) {
			
			// The exploration behavior.
			case State.EXPLORE:
			
				explore ();

				// The transition conditions to another state.
				if (transportingFood) {
					activeState = State.TRANSPORT_FOOD;
				}
				if (foundPheromone) {
					activeState = State.FOLLOW_TRAIL;
				}

				break;
			
			// The behavior for following a pheromone trail.
			case State.FOLLOW_TRAIL:
			
				followTrail ();

				// The transition conditions to another state.
				if (transportingFood) {

					activeState = State.TRANSPORT_FOOD;
				}

				if (!foundFood) {
					activeState = State.EXPLORE;
				}

				break;
			
			// The food transportation behavior.
			case State.TRANSPORT_FOOD:
			
				transportFood ();

				// The transition conditions to another state.
				if (!transportingFood) {

					if (foodLocation != Vector3.zero) {
						activeState = State.FOLLOW_TRAIL;
					} else {
						activeState = State.EXPLORE;
					}
				}

				break;
		}
	}
Example #12
0
 public Project(string name, DateTime startDate, string details, State projectState)
 {
     this.Name = name;
     this.StartDate = startDate;
     this.Details = details;
     this.State = projectState;
 }
Example #13
0
        public override void Update(State s, Room room)
        {
            base.Update(s, room);
            Vector2 direction = new Vector2((float)((TargetX - x) * (DiverGame.Random.NextDouble() * 0.2f + 0.8f)),
                                            (float)((TargetY - y) * (DiverGame.Random.NextDouble() * 0.2f + 0.8f)));

            if(direction.LengthSquared() > 0)
                direction.Normalize();

            speedX += direction.X * 0.007f;
            speedY += direction.Y * 0.007f;
            speedX *= 0.999f;
            speedY *= 0.999f;

            float speed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
            animationGridFrame += speed * 0.25f + 0.03f;

            x += speedX;
            y += speedY;
            X = (int)x;
            Y = (int)y;

            float desiredRot = (float)Math.Atan2(speedX, -speedY) - (float)Math.PI / 2f;
            float rotDiff = desiredRot - rotation;
            while (rotDiff > MathHelper.Pi) rotDiff -= MathHelper.TwoPi;
            while (rotDiff < -MathHelper.Pi) rotDiff += MathHelper.TwoPi;
            rotation += rotDiff * 0.1f;
        }
Example #14
0
 public bool CanExecute(State s)
 {
     if (_prejudicates.Any(l => !l(s))) return false;
     if (_requires.Any(l => !s.Has(l.Key))) return false;
     if (_consumes.Any(l => !s.Sufficient(l.Key, l.Value))) return false;
     return true;
 }
		private void SetTouchState(State state, Vector2D position)
		{
			if (touch == null)
				return; //ncrunch: no coverage
			touch.SetTouchState(0, state, position);
			AdvanceTimeAndUpdateEntities();
		}
Example #16
0
 private State[] getNeighbourStates(int position)
 {
     State[] neighbourStates = new State[4];
     if (position == 0)
     {
         neighbourStates[0] = previousCells[SIZE - 1].getCurrentState;
         neighbourStates[1] = previousCells[position].getCurrentState;
         neighbourStates[2] = previousCells[position].getNextState;
         neighbourStates[3] = previousCells[position + 1].getCurrentState;
     }
     else if (position == SIZE - 1)
     {
         neighbourStates[0] = previousCells[SIZE - 2].getCurrentState;
         neighbourStates[1] = previousCells[position].getCurrentState;
         neighbourStates[2] = previousCells[position].getNextState;
         neighbourStates[3] = previousCells[0].getCurrentState;
     }
     else
     {
         neighbourStates[0] = previousCells[position - 1].getCurrentState;
         neighbourStates[1] = previousCells[position].getCurrentState;
         neighbourStates[2] = previousCells[position].getNextState;
         neighbourStates[3] = previousCells[position + 1].getCurrentState;
     }
     return neighbourStates;
 }
    IEnumerator Attack()
    {
        pathfinder.enabled = false;
        currentState = State.Attacking;

        Vector3 OriginalPos = transform.position;
        Vector3 dirToTarget = (target.position - transform.position).normalized;
        Vector3 attackPos = target.position - dirToTarget * (myCollisionRadius);

        float attackSpeed = 3;
        float percent = 0;

        enemySkinMaterial.color = Color.red;
        bool hasAppliedDamage = false;

        while (percent <= 1) {

            if(percent >= 0.5f && !hasAppliedDamage){
                hasAppliedDamage = true;
                targetEntity.TakeDamage(damage);
            }

            percent += Time.deltaTime * attackSpeed;
            float interpolation = (-Mathf.Pow(percent, 2) + percent) * 4;
            transform.position = Vector3.Lerp (OriginalPos, attackPos, interpolation);

            yield return null;
        }
        enemySkinMaterial.color = enemyOriginalColor;
        currentState = State.Chasing;
        pathfinder.enabled = true;
    }
        public override Activity Tick(Actor self)
        {
            switch (state)
            {
                case State.Wait:
                    return this;
                case State.Turn:
                    state = State.DragIn;
                    return Util.SequenceActivities(new Turn(112), this);
                case State.DragIn:
                    state = State.Dock;
                    return Util.SequenceActivities(new Drag(startDock, endDock, 12), this);
                case State.Dock:
                    ru.PlayCustomAnimation(self, "dock", () => { ru.PlayCustomAnimRepeating(self, "dock-loop"); state = State.Loop; });
                    state = State.Wait;
                    return this;
                case State.Loop:
                    if (!proc.IsInWorld || proc.IsDead() || harv.TickUnload(self, proc))
                        state = State.Undock;
                    return this;
                case State.Undock:
                    ru.PlayCustomAnimBackwards(self, "dock", () => state = State.DragOut);
                    state = State.Wait;
                    return this;
                case State.DragOut:
                    return Util.SequenceActivities(new Drag(endDock, startDock, 12), NextActivity);
            }

            throw new InvalidOperationException("Invalid harvester dock state");
        }
 // Use this for initialization
 void Start()
 {
     GameObject groupped =  GameObject.Find("SpawnerGroup");
     SpawnerGroupScript scripta = groupped.GetComponent<SpawnerGroupScript>();
     spawnInterval = scripta.spawnInterval;
     state = State.SPAWNING;
 }
Example #20
0
		protected void Initialize()
		{
			connections = new List<Connection>();
			inputs = new List<int>();
			actionState = State.Integrating;
			CurrentMembranePotential = config.RestingPotential;
		}
        public void OnNetworkData(double time, Vector3 position, Quaternion rotation)
        {
            // Shift the buffer sideways, deleting state 20
            for (int i = m_BufferedState.Length - 1; i >= 1; i--)
            {
                m_BufferedState[i] = m_BufferedState[i - 1];
            }

            // Record current state in slot 0
            State state = new State();
            state.timestamp = time;
            state.pos = position;
            state.rot = rotation;

            m_BufferedState[0] = state;

            // Update used slot count, however never exceed the buffer size
            // Slots aren't actually freed so this just makes sure the buffer is
            // filled up and that uninitalized slots aren't used.
            m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);

            // Check if states are in order, if it is inconsistent you could reshuffel or
            // drop the out-of-order state. Nothing is done here
            for (int i = 0; i < m_TimestampCount - 1; i++)
            {
                if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
                    Debug.Log("State inconsistent");
            }
        }
Example #22
0
        public World(IControls controls)
        {
            _controls = controls;

            _start = new State
            {
                Update = StartUpdate,
                Draw = StartDraw
            };
            _alive = new State
            {
                Update = AliveUpdate,
                Draw = AliveDraw
            };
            _dead = new State
            {
                Update = DeadUpdate,
                Draw = DeadDraw
            };
            _gameOver = new State
            {
                Update = GameOverUpdate,
                Draw = GameOverDraw
            };

            _state = _start;
            _viewer = new Viewer();
            _bird = new Bird(controls);
            _pipeCollection = new PipeCollection();
        }
Example #23
0
 /// <summary>
 /// Create an instance of ModelProgramProvider for a given assembly
 /// </summary>
 /// <param name="modelAssemblyFile">The full path to the assembly file.</param>
 /// <param name="generator">Optional parameter generator.</param>
 public ModelProgramProvider(string modelAssemblyFile, ParameterGenerator/*?*/ generator)
 {
     modelAssembly = Assembly.LoadFrom(modelAssemblyFile);
     this.generator = generator;
     Initialize();
     initialState = GetState();
 }
Example #24
0
 void stateCell1()
 {
     text.text = "You've picked up the mirror, but the cell still looks bad.\n\n" +
             "[S to view Sheets, L to view Lock]";
     if (Input.GetKeyDown (KeyCode.S)) {currState = State.sheets1;}
     else if (Input.GetKeyDown (KeyCode.L)) {currState = State.lock1;}
 }
Example #25
0
 // Use this for initialization
 void Start()
 {
     m_eState = State.A2B;
     transform.position = m_tPatrolPointA.position;
     m_tOrigin = m_tPatrolPointA;
     m_tTarget = m_tPatrolPointB;
 }
Example #26
0
 void stateMirror()
 {
     text.text = "The dirty old mirror on the wall seems loose.\n\n" +
             "[T to take the mirror, R to return to roaming your cell]";
     if (Input.GetKeyDown (KeyCode.T)) {currState = State.cell1;}
     else if (Input.GetKeyDown (KeyCode.R)) {currState = State.cell;}
 }
Example #27
0
        public EventDevelopment(DevelopmentState a_backState, LinkedList<Event> a_events)
        {
            if (a_events == null)
            {
                throw new ArgumentNullException();
            }
            m_numOfAddedEvents = 0;
            m_state = State.neutral;
            m_backState = a_backState;
            m_buttonList = new LinkedList<Button>();
            m_guiList = new LinkedList<GuiObject>();
            m_buttonsToAdd = new Stack<Button>();
            m_buttonsToRemove = new Stack<Button>();

            m_eventsToRemove = new Stack<Button>();
            m_eventsToAdd = new Stack<Event>();
            m_events = new Dictionary<Button, Event>();
            m_effects = new Dictionary<Button, EventEffect>();
            m_triggers = new Dictionary<Button, EventTrigger>();
            m_stateButtons = new Stack<LinkedList<Button>>();

            foreach (Event t_e in a_events)
            {
                addEvent(t_e);
            }
        }
 public TenguBossStateMachine()
 {
     currState = 0;
     hold = 0;
     moveCount = 0;
     Random.seed = System.DateTime.Today.Millisecond;
 }
Example #29
0
 private void opeation_Click(object sender, EventArgs e)
 {
     Button btn = sender as Button;
     firstNumber = double.Parse(display.Text);
     state = State.WaitingForSecondNumber;
     operation = btn.Text;
 }
Example #30
0
	// Update is called once per frame
	void Update () {
		switch (state) {
		case State.IDLE:
			if(ball.transform.position.x > 0)//ball on ai side
			{
				attack_offset = Random.Range(0.25f, 0.8f);
				state = State.ATTACK;
				break;
			}
			if (idle_pos.x < transform.position.x)
				goLeft();
			if (transform.position.x < idle_pos.x)
				goRight();
			break;
		case State.ATTACK:
			if(ball.transform.position.x < 0) //ball on player side
			{
				float x = Random.Range(min_x, max_x - 3);
				idle_pos.x = x;
				state = State.IDLE;
				break;
			}
			if (ball.transform.position.x + attack_offset < transform.position.x)
				goLeft();
			if (ball.transform.position.x > transform.position.x - attack_offset)
				goRight();
			break;
		default:
			break;
		}
	}