public bool CanTurnInDirection(TurnDirection direction)
 {
     switch (direction)
     {
         case TurnDirection.YawClockwise:
             if (torque.y < -.9f)
                 return true;
             break;
         case TurnDirection.YawCounterclock:
             if (torque.y > .9f)
                 return true;
             break;
         case TurnDirection.RollRight:
             if (torque.z > .9f)
                 return true;
             break;
         case TurnDirection.RollLeft:
             if (torque.z < -.9f)
                 return true;
             break;
         case TurnDirection.PitchUp:
             if (torque.x > .9f)
                 return true;
             break;
         case TurnDirection.PitchDown:
             if (torque.x < -.9f)
                 return true;
             break;
         default:
             break;
     }
     return false;
 }
 public ExpressConveyorBelt(Board board, Tile baseTile, TileDirection direction, TurnDirection turn, int x,
     int y)
     : base(board, baseTile, x, y)
 {
     Direction = direction;
     Turn = turn;
 }
Exemple #3
0
        public static char GetChar(TurnDirection td)
        {
            switch (td)
            {
                case TurnDirection.Left:
                    return 'L';

                case TurnDirection.Right:
                    return 'R';

                case TurnDirection.Both:
                    return 'B';
            }
            return 'N';
        }
Exemple #4
0
        public Worm(GamePlayScreen scr, Color col)
        {
            color = col;
            screen = scr;
            turning = TurnDirection.None;

            spriteBatch = screen.ScreenManager.SpriteBatch;

            LoadContent();

            Rectangle spawnfield = new Rectangle(100, 100, screen.ScreenManager.Game.GraphicsDevice.Viewport.Width - 120 - 200, screen.ScreenManager.Game.GraphicsDevice.Viewport.Height - 200);

            setDirection(360.0 * screen.Random.NextDouble());
            head_position = new Vector2(spawnfield.Left + spawnfield.Width * (float)screen.Random.NextDouble(),
                spawnfield.Top + spawnfield.Height * (float)screen.Random.NextDouble());

            AddPoint(CurrentVector());
        }
Exemple #5
0
        public async Task TurnAsync(int degree, TurnDirection direction,
            DrivingMethod drivingMethod = DrivingMethod.FullStep)
        {
            int steps;
            GpioPinValue[][] methodSequence;
            switch (drivingMethod)
            {
                case DrivingMethod.WaveDrive:
                    methodSequence = _waveDriveSequence;
                    steps = (int)Math.Ceiling(degree / 0.1767478397486253);
                    break;
                case DrivingMethod.FullStep:
                    methodSequence = _fullStepSequence;
                    steps = (int)Math.Ceiling(degree / 0.1767478397486253);
                    break;
                case DrivingMethod.HalfStep:
                    methodSequence = _haveStepSequence;
                    steps = (int)Math.Ceiling(degree / 0.0883739198743126);
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(drivingMethod), drivingMethod, null);
            }
            var counter = 0;
            while (counter < steps)
            {
                for (var j = 0; j < methodSequence[0].Length; j++)
                {
                    for (var i = 0; i < 4; i++)
                    {
                        _gpioPins[i].Write(methodSequence[direction == TurnDirection.Right ? i : 3 - i][j]);
                    }
                    await Task.Delay(5);
                    counter++;
                    if (counter == steps)
                        break;
                }
            }

            Stop();
        }
        public Dictionary<CommandFields, short> Update(Robot robot, MonteCarloLocalization localization, Stopwatch stopwatch)
        {
            Dictionary<CommandFields, short> outputState = new Dictionary<CommandFields, short>();

            // Check for start pulse
            if (!started)
            {
                // Set flag
                started = true;
                // Record start time
                startTime = stopwatch.ElapsedMilliseconds;
                // Set state
                state = AlgorithmState.LiftingScoop;
            }

            switch (state)
            {
                case AlgorithmState.LiftingScoop:
                    // Check arm swing limit
                    if (robot.TelemetryFeedback.ScoopUpperLimitSwitchDepressed)
                    {
                        Console.WriteLine("Lifting scoop");
                        // Move to next stage
                        state = AlgorithmState.Spinning;
                        // Save time
                        startTime = stopwatch.ElapsedMilliseconds;
                        // Set state
                        outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.BucketPivot] = 0;
                    }
                    else
                    {
                        Console.WriteLine("Scoop lifted");
                        // Set state
                        outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.BucketPivot] = 1000;
                    }
                    break;
                case AlgorithmState.Spinning:
                    long elapsedTime = stopwatch.ElapsedMilliseconds - startTime;
                    if (elapsedTime > configuration.LocalizationTurnDuration)
                    {
                        // Change direction
                        if (turnDirection == TurnDirection.Left)
                            turnDirection = TurnDirection.Right;
                        else
                            turnDirection = TurnDirection.Left;

                        // Reset start timer
                        startTime = stopwatch.ElapsedMilliseconds;
                    }

                    // Check convergence of MCL
                    if (localization.Confidence > configuration.DesiredLocalizationConfidence)
                    {
                        Console.WriteLine("MCL converged");
                        // Set flag
                        state = AlgorithmState.Done;

                        // Set state
                        outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.BucketPivot] = 0;
                    }
                    else
                    {
                        Console.WriteLine("Spinning in place, MCL confidence: " + localization.Confidence);

                        // Set static state
                        outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = (short)turnDirection;
                        outputState[Comms.CommandEncoding.CommandFields.BucketPivot] = 0;

                        // Check reinitialize
                        if (elapsedTime > configuration.ConvergenceAllowance)
                        {
                            // Reinitialize the MCL algorithm
                            localization.Initialize(robot);
                            // Reset timer
                            startTime = stopwatch.ElapsedMilliseconds;
                        }
                    }
                    break;
                case AlgorithmState.Done:
                    // Set state
                    outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.BucketPivot] = 1000;
                    break;
                default:
                    break;
            }
            // Static state
            outputState[Comms.CommandEncoding.CommandFields.BucketPitch] = 0;
            outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = 0;
            outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = 0;
            outputState[Comms.CommandEncoding.CommandFields.RangeFinderServo] = 90;

            return outputState;
        }
Exemple #7
0
        public void Turn(TurnDirection turn)
        {
            if (driveAvailable)
            {
                int enlarger = turn == TurnDirection.CW ? 1 : -1;
                for (int i = 0; i <= 1; i++)
                {
                    if (Math.Abs(driveWheels[i].Angle.Y + enlarger) <= 30)
                        driveWheels[i].Angle.Y += enlarger;
                }
                if (speed != 0)
                    this.Angle.Y += enlarger;

                turnFlag = true;
                frame = 0;
            }
        }
Exemple #8
0
        public void Update(GameTime gameTime)
        {
            if (screen.TransitionPosition == 0)
            {
                //Hole?
                if (!making_hole && screen.Random.NextDouble() < Settings.Worm.hole_chance)
                {
                    making_hole = true;
                    hole_begin_time = gameTime.TotalGameTime.Ticks;
                }
                else if (making_hole && gameTime.TotalGameTime.Ticks > Settings.Worm.hole_time + hole_begin_time)
                {
                    making_hole = false;
                    hole_begin_time = 0;
                }

                //Turning
                if (turning != TurnDirection.None)
                {
                    double V = Math.Atan2(head_direction.Y, head_direction.X);

                    if (turning == TurnDirection.Left)
                        V -= gameTime.ElapsedGameTime.Ticks * Settings.Worm.turnspeed;
                    else if (turning == TurnDirection.Right)
                        V += gameTime.ElapsedGameTime.Ticks * Settings.Worm.turnspeed;

                    setDirection(V);

                    turning = TurnDirection.None;
                }

                //New position
                head_position.X += head_direction.X * Settings.Worm.movespeed * gameTime.ElapsedGameTime.Ticks;
                head_position.Y += head_direction.Y * Settings.Worm.movespeed * gameTime.ElapsedGameTime.Ticks;

                if (!making_hole && Settings.Worm.point_resolution < (gameTime.TotalGameTime.Ticks - last_point_time))
                {
                    AddPoint(CurrentVector());
                    last_point_time = gameTime.TotalGameTime.Ticks;
                }
            }
        }
 //assigns XdistanceFromPLayer with the absolute distance from player,
 //also creates the angle, speed, and turn direction
 //also sets curveInt to 0
 void AssignCircle()
 {
     curveInt = 0;
     XDistanceFromPlayer = Player.transform.position.x - transform.position.x;
     if (XDistanceFromPlayer < 0)
     {
         XDistanceFromPlayer *= -1;
     }
     CurveAngle = 180 / CurveCount;
     CurveSpeed = ((XDistanceFromPlayer * 3.14f) / 2f) / CurveCount;
     if (transform.position.x < Player.transform.position.x)
     {
         turn = TurnDirection.right;
     }
     else if (transform.position.x > Player.transform.position.x)
     {
         turn = TurnDirection.left;
     }
 }
 /// <summary>
 /// Creates a new instance of the <see cref="TurnCommand"/> class
 /// </summary>
 /// <param name="turnDirection">The direction the robot is instructed to turn</param>
 public TurnCommand(TurnDirection turnDirection)
 {
     TurnDirection = turnDirection;
 }
Exemple #11
0
        /// <summary>
        /// Turnning one step in specifies direction.
        /// </summary>
        /// <param name="direction">The turnning direction.</param>
        /// <remarks>You can call this function only 
        /// the <see cref="AutoTurn"/> is set to <c>false</c>.</remarks>
        public void TrunOnStep(TurnDirection direction)
        {
            if (AutoTurn)
                return;
            if (CarouselCanvas != null)
            {
                double perAngle = _2PI / CarouselCanvas.Children.Count;
                foreach (var item in CarouselCanvas.Children)
                {
                    CarouselItem cItem = item as CarouselItem;
                    if (cItem != null)
                    {
                        if (direction == TurnDirection.Clockwise)
                        {
                            cItem.Angle += perAngle;
                        }
                        else
                        {
                            cItem.Angle -= perAngle;
                        }

                        // if overceed 2 PI, then adjust it
                        if (cItem.Angle > _2PI)
                        {
                            cItem.Angle -= _2PI;
                        }
                        else if (cItem.Angle < -_2PI)
                        {
                            cItem.Angle += _2PI;
                        }
                    }
                }
            }
        }
 private void Turn(TurnDirection direction)
 {
     CurrentPosition.SetOrientation(direction);
 }
Exemple #13
0
    // Update is called once per frame
    void Update()
    {
        elapsedTime += Time.deltaTime;
        if (!ScoreManager.inst.GameOver)
        {
            forwardSpeed += elapsedTime * 0.005f;
        }

        Vector3 deltaMove   = transform.forward * forwardSpeed;
        Vector3 lateralMove = Vector3.zero;

        switch (state)
        {
        case State.Default:
        {
            float horizontal = Input.GetAxisRaw("Horizontal");

            Vector3 toCenter = Vector3.Project(transform.position - railOrigin.position, railOrigin.right);
            // go back to origin if not holding down any keys
            if (horizontal == 0f)
            {
                lateralMove = -toCenter;        // new Vector3(-transform.localPosition.x, 0.0f, 0.0f);
            }
            else
            {
                // clamp position
                if (toCenter.magnitude < lateralRange)
                {
                    lateralMove = transform.right * horizontal;
                }
            }
        }
        break;

        case State.Turning:
            // move according to target forward
            deltaMove = railOrigin.forward * forwardSpeed;

            float angle = turnsPerSecond * targetAngle * Time.deltaTime;
            if (Mathf.Abs(degreesTurned + angle) >= 90f)
            {
                // rotate the leftover amount and exit
                angle         = targetAngle - degreesTurned;
                degreesTurned = 0f;

                if (ScoreManager.inst.GameOver)
                {
                    state = State.GameOver;
                }
                else
                {
                    state = State.Default;
                }
            }
            else
            {
                // rotate full amount
                degreesTurned += angle;
            }
            transform.Rotate(Vector3.up, angle);
            break;

        case State.OnTrigger:
        {
            // keep moving towards center
            Vector3 toCenter = Vector3.Project(transform.position - railOrigin.position, railOrigin.right);
            lateralMove = -toCenter;

            TurnDirection direction = TurnDirection.None;

            if (Input.GetKeyDown(KeyCode.A))
            {
                direction = TurnDirection.Left;
            }
            else if (Input.GetKeyDown(KeyCode.D))
            {
                direction = TurnDirection.Right;
            }

            if (direction != TurnDirection.None)
            {
                bool success = Turn(intersectingRouter, direction);
                state = State.Turning;

                if (success)
                {
                    ScoreManager.inst.PlayerScored();
                }
                else
                {
                    ScoreManager.inst.FailedTurn();
                }
            }
        }
        break;

        case State.TriggerExit:
        {
            TurnDirection direction = TurnDirection.Straight;
            bool          success   = Turn(intersectingRouter, direction);
            state = State.Default;
            if (success)
            {
                ScoreManager.inst.PlayerScored();
            }
            else
            {
                ScoreManager.inst.FailedTurn();
            }
        }
        break;

        case State.GameOver:
        {
        }
        break;

        default:
            break;
        }

        deltaMove += lateralMove * lateralSpeed;
        controller.Move(deltaMove * Time.deltaTime);
    }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="initialLane"></param>
 /// <param name="finalLane"></param>
 /// <param name="interconnect"></param>
 public TurnState(LaneID initialLane, LaneID finalLane, InterconnectID interconnect, TurnDirection turnDirection)
     : base(initialLane, finalLane, interconnect)
 {
     this.TurnDirection = turnDirection;
 }
 public RobotUTurnAction(TurnDirection direction, TurnDirection?initialLookDirection = null)
 {
     m_turnDirection        = direction;
     m_initialLookDirection = initialLookDirection;
 }
Exemple #16
0
 public virtual bool Turn(TurnDirection direction)
 {
     return(true);
 }
Exemple #17
0
 public override void Turn(TurnDirection direction)
 {
 }
Exemple #18
0
        public Dictionary<CommandFields, short> Update(Robot robot, Stopwatch stopwatch)
        {
            Dictionary<CommandFields, short> outputState = new Dictionary<CommandFields, short>();

            // Check for start pulse
            if (!started)
            {
                // Set flag
                started = true;
                // Record start time
                startTime = stopwatch.ElapsedMilliseconds;
                // Set state
                state = AlgorithmState.LiftingBin;
            }

            switch (state)
            {
                case AlgorithmState.FinePositioning:
                    // Read proximity sensors
                    outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = 0;
                    // Calcualte error
                    double error = robot.TelemetryFeedback.RearProximityRight - robot.TelemetryFeedback.RearProximityLeft;
                    // Check for position converged
                    if ((robot.TelemetryFeedback.RearProximityLeft - robot.TelemetryFeedback.RearProximityRight) < 10)
                        state = AlgorithmState.LiftingBin;
                    break;
                case AlgorithmState.LiftingBin:
                    // Set state
                    outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = 1000;
                    outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = 1000;

                    // Check for bin fully raised
                    if (robot.TelemetryFeedback.BinUpperSwitchDepressed)
                    {
                        state = AlgorithmState.WiggleRotational;
                        // Store start time
                        startTime = stopwatch.ElapsedMilliseconds;
                    }
                    break;
                case AlgorithmState.WiggleRotational:
                    // Calculate time
                    long elapsedTime = stopwatch.ElapsedMilliseconds - startTime;

                    if (elapsedTime > 1500)
                    {
                        // Change direction
                        if (turnDirection == TurnDirection.Left)
                            turnDirection = TurnDirection.Right;
                        else
                            turnDirection = TurnDirection.Left;

                        // Increment counter
                        turnCount++;

                        // Reset start timer
                        startTime = stopwatch.ElapsedMilliseconds;
                    }

                    // Check convergence of MCL
                    if (turnCount > 3)
                    {
                        Console.WriteLine("Done wiggling");
                        // Set flag
                        state = AlgorithmState.LoweringBin;

                        // Set state
                        outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = 0;
                    }
                    else
                    {
                        // Set static state
                        outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = (short)turnDirection;
                        outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = 0;
                        outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = 0;
                    }

                    break;
                case AlgorithmState.LoweringBin:
                    Console.WriteLine("Lowering bin");
                    outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = -1000;
                    outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = -1000;

                    // Check for bin fully raised
                    if (robot.TelemetryFeedback.BinLowerSwitchDepressed)
                        state = AlgorithmState.Done;
                    break;
                case AlgorithmState.Done:
                    Console.WriteLine("Done");
                    // Set state
                    outputState[Comms.CommandEncoding.CommandFields.TranslationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.RotationalVelocity] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.LeftBucketActuator] = 0;
                    outputState[Comms.CommandEncoding.CommandFields.RightBucketActuator] = 0;
                    break;
                default:
                    break;
            }

            // Static outputs
            outputState[Comms.CommandEncoding.CommandFields.BucketPivot] = 0;
            outputState[Comms.CommandEncoding.CommandFields.BucketPitch] = 0;
            outputState[Comms.CommandEncoding.CommandFields.RangeFinderServo] = 90;

            return outputState;
        }
Exemple #19
0
 private string TurnResult(TurnDirection turnDirection)
 {
     return($"Turned {turnDirection.ToString().ToLower()} towards {CurrentOrientation.ToString()}");
 }
Exemple #20
0
 // The turnning direction changed
 private void TurnDirectionChanged(TurnDirection direction)
 {
     if (CarouselCanvas != null)
     {
         Storyboard sb = BuildStoryboard(CarouselCanvas.Children, direction);
         if (AutoTurn)
             sb.Begin();
     }
 }
 public SpecialTrackPiece(Point location, TurnDirection direction)
 {
     this.location  = location;
     this.type      = Types.TURN;
     this.direction = direction;
 }
Exemple #22
0
    // Use this for initialization
    void Start()
    {
        Application.targetFrameRate = 60;

        for (int i = 0; i < boxesToDestroy.Length; i++)
        {
            boxesToDestroy[i] = null;
        }

        rateShort  = 1.0f / 3;
        rateMedium = 1.0f / 3;

        nextTurnDirection = TurnDirection.LEFT;

        for (int i = 0; i < 3; i++)
        {
            GenerateNextBox(false);
        }

        txtScore.text = score.ToString();

        best = PlayerPrefs.GetInt("best", 0);
        if (lastBest == -1)
        {
            lastBest = best;
        }

        if (best == 0)
        {
            txtBest.gameObject.SetActive(false);
        }
        else
        {
            if (best != lastBest)
            {
                iTween.ValueTo(gameObject, iTween.Hash("from", lastBest, "to", best, "time", 0.5f, "onupdate", "UpdateBest"));

                float bigScale = 1.5f;
                float time     = 0.5f;

                iTween.ScaleTo(txtBest.gameObject, iTween.Hash("scale", new Vector3(bigScale, bigScale, 1), "easetype", "easeInOutSine", "time", time));
                iTween.ScaleTo(txtBest.gameObject, iTween.Hash("scale", new Vector3(1, 1, 1), "easetype", "easeInOutSine", "time", time, "delay", time));
            }
            else
            {
                txtBest.text = "BEST " + best.ToString();
            }

            txtBest.gameObject.SetActive(true);
        }

        lastBest = best;

        /*
         * currentColor = new Color(84 / 255.0f, 140 / 255.0f, 215 / 255.0f, 1);
         *
         * // color correction
         * Vector3 hcy = SCR_ColorConverter.RGBToHCY(new Vector3(currentColor.r, currentColor.g, currentColor.b));
         * hcy.y = 1;
         * hcy.z += 0.075f;
         * Vector3 rgb = SCR_ColorConverter.HCYToRGB(hcy);
         * currentColor = new Color(rgb.x, rgb.y, rgb.z, 1);
         */
        colorIndex   = Random.Range(0, MAT_BOXES.Length);
        currentColor = MAT_BOXES[colorIndex].color;

        GenerateNextColor();

        matBox.color      = currentColor;
        matCylinder.color = currentColor;

        iTween.ValueTo(gameObject, iTween.Hash("from", 0, "to", 1, "time", 1f, "easetype", "easeInOutSine", "onupdate", "UpdateTapToPlay", "looptype", "pingPong", "ignoretimescale", true));

        txtTapToPlay.gameObject.SetActive(true);

        scrCamera = Camera.main.GetComponent <SCR_Camera>();

        if (numberGems > lastNumberGems)
        {
            iTween.ValueTo(gameObject, iTween.Hash("from", lastNumberGems, "to", numberGems, "time", 0.5f, "onupdate", "UpdateGems", "ignoretimescale", true));

            float bigScale = 1.5f;
            float time     = 0.5f;

            iTween.ScaleTo(gemNumber, iTween.Hash("scale", new Vector3(bigScale, bigScale, 1), "easetype", "easeInOutSine", "time", time, "ignoretimescale", true));
            iTween.ScaleTo(gemNumber, iTween.Hash("scale", new Vector3(1, 1, 1), "easetype", "easeInOutSine", "time", time, "delay", time, "ignoretimescale", true));
            iTween.ScaleTo(gemImage, iTween.Hash("scale", new Vector3(bigScale, bigScale, 1), "easetype", "easeInOutSine", "time", time, "ignoretimescale", true));
            iTween.ScaleTo(gemImage, iTween.Hash("scale", new Vector3(1, 1, 1), "easetype", "easeInOutSine", "time", time, "delay", time, "ignoretimescale", true));
        }
        else
        {
            gemNumber.GetComponent <Text>().text = numberGems.ToString();
        }

        lastNumberGems = numberGems;

        Time.timeScale = speedMin;

        state = State.READY;

                #if UNITY_ANDROID
        string appId = "ca-app-pub-0081066185741622~3790493478";
                #elif UNITY_IPHONE
        string appId = "ca-app-pub-0081066185741622~1392680402";
                #else
        string appId = "unexpected_platform";
                #endif

        // Initialize the Google Mobile Ads SDK.
        MobileAds.Initialize(appId);

        RequestInterstitial();
    }
        public void TurnMower(int gardenLength, int gardenWidth, int startX, int startY, Orientation orientation, TurnDirection turnDirection, Orientation expectedOrientation)
        {
            var      context         = new MoveMowerTestContext();
            Position currentPosition = new Position(new Coordinates(startX, startY), orientation);

            "Given I have a garden"
            .x(() => context.Garden = new Garden(gardenLength, gardenWidth));
            "And I have started a new Mower inside the garden"
            .x(() => context.Mower = this.CreateNewMower(context.Garden, startX, startY, orientation));
            "When I turn the Mower"
            .x(() => context.Mower.Turn(turnDirection));
            "Then its orientation should be as expected"
            .x(() => context.Mower.GetPosition().Orientation.Should().Be(expectedOrientation));
        }
Exemple #24
0
 public void Turn(TurnDirection turn)
 {
     turning = turn;
 }
Exemple #25
0
 public Turn()
 {
     players            = new List <Player>();
     currentPlayerIndex = 0;
     turnDirection      = TurnDirection.Ascending;
 }
Exemple #26
0
 public Gear(Board board, Tile baseTile, TurnDirection direction, int x, int y) : base(board, baseTile, x, y)
 {
     Turn = direction;
 }
 public TurntableTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
 {
     TurnDirection = kvp.GetEnum("turn_direction", TurnDirection.Left);
     Animation     = kvp.GetString("animation", null);
     Sound         = kvp.GetString("sound", null);
 }
Exemple #28
0
 public Gear(Board board, Tile baseTile, TurnDirection direction, int x, int y)
     : base(board, baseTile, x, y)
 {
     Turn = direction;
 }
Exemple #29
0
        protected static TurnDirection GetTurnDirection(Robot robot, TileCoordinates position, FlatDirection direction, TurnDirection preference, out bool o_uTurn, bool ignoreMovingObjects)
        {
            var left  = direction.RotateLeft();
            var right = direction.RotateRight();

            bool canGoLeft  = CanEnter(robot, position.Move(left), left, ignoreMovingObjects);
            bool canGoRight = CanEnter(robot, position.Move(right), right, ignoreMovingObjects);

            if (canGoRight && !canGoLeft)
            {
                o_uTurn = false;
                return(TurnDirection.Right);
            }
            else if (canGoLeft && !canGoRight)
            {
                o_uTurn = false;
                return(TurnDirection.Left);
            }
            else
            {
                o_uTurn = (!canGoLeft && !canGoRight);
                return(preference);
            }
        }
 public LowRiskLocalization(AutonomyConfiguration configuration)
 {
     this.configuration = configuration;
     this.turnDirection = TurnDirection.Right;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="initial"></param>
 /// <param name="final"></param>
 /// <param name="interconnect"></param>
 /// <param name="turnDirection"></param>
 public WaitingAtStopState(LaneID initial, LaneID final, InterconnectID interconnect, TurnDirection turnDirection)
     : base(initial, final, interconnect)
 {
     this.TurnDirection = turnDirection;
 }
Exemple #32
0
 public TurnCommand(Toy toy, TurnDirection turnDirection)
     : base(toy)
 {
     this._toy.TurnToDirection = turnDirection;
 }
 public void Turn(TurnDirection direction, double angle = 5)
 {
     Movement?.Turn(Character, direction, angle);
 }
Exemple #34
0
 public Deposition(AutonomyConfiguration configuration)
 {
     // Assign fields
     this.configuration = configuration;
     this.turnDirection = TurnDirection.Right;
 }
        public async Task TurnByKeyPress(List <MovableCharacter> charactersToTurn, Key key)
        {
            TurnDirection turnDirection = GetDirectionFromKey(key);

            await Turn(charactersToTurn, turnDirection);
        }
    public void TurnWheel(TurnDirection direction)
    {
        switch(direction)
            {
                case TurnDirection.Left:
                    break;
                case TurnDirection.Right:
                    break;
                case TurnDirection.Center:
                    break;
                default:
                    break;

            }
    }
        public ulong DetermineDurationOfTurn(Angle start, Angle end, Angle turnRate, TurnDirection turnDirection)
        {
            if (turnDirection == TurnDirection.Clockwise)
            {
                if (end > start)
                {
                    end = new Angle(end.Value - (Math.PI * 2));
                }
            }

            if (turnDirection == TurnDirection.AntiClockwise)
            {
                if (end < start)
                {
                    end = new Angle(end.Value + (Math.PI * 2));
                }
            }
            var turnAngle = start - end;
            var stuff = (turnAngle.Value / turnRate.Value) * -1000.0;
            return (ulong)(Math.Round(stuff));
        }
Exemple #38
0
        /// <summary>
        /// Create the total storyboard contains all item's animations. 
        /// </summary>
        /// <param name="items">The carousel items collection.</param>
        /// <param name="direction">The carousel turnning direction.</param>
        /// <returns>The storyboard just created.</returns>
        private Storyboard BuildStoryboard(UIElementCollection items, TurnDirection direction)
        {
            // The carousel storyboard
            Storyboard sb = null;

            if (this.Resources.Contains(CarouselStoryboardKey))
            {
                // if already in resources, get from resources
                sb = this.Resources[CarouselStoryboardKey] as Storyboard;
                // Must stop it before we change it
                sb.Stop();
                // and clear the children
                sb.Children.Clear(); // because we rebuild all item
            }
            else
            {
                sb = new Storyboard();
                // Add to resources dictionary
                this.Resources.Add(CarouselStoryboardKey, sb);
            }

            // Now, we start build each item's storyboard
            int itemsCount = items.Count;
            double perAngle=_2PI / itemsCount;
            double by = _2PI;
            for (int i = 0; i < itemsCount; i++)
            {
                double angle = i * perAngle + Math.PI / 2;

                // We only care the carouselitem
                CarouselItem item = items[i] as CarouselItem;
                if (item != null)
                {
                    item.Angle = angle;

                    // Add item's storyboard to main storyboard
                    if (direction == TurnDirection.Clockwise)
                    {
                        sb.Children.Add(BuildStoryboard(item, by, Duration));
                    }
                    else
                    {
                        sb.Children.Add(BuildStoryboard(item, -by, Duration));
                    }
                }
            }

            return sb;
        }
        public Angle DetermineTurnRate(double speed, double radius, TurnDirection turnDirection)
        {
            var turnTime = (Math.PI * radius) / speed;

            double turnRate = Math.PI / turnTime;

            if (turnDirection == TurnDirection.Clockwise)
            {
                turnRate = -turnRate;
            }

            return new Angle(turnRate);
        }
 public async Task Turn(MovableCharacter characterToTurn, TurnDirection direction, double angle = 5)
 {
     await Turn(new List <MovableCharacter> {
         characterToTurn
     }, direction, angle);
 }
Exemple #41
0
        private void ChangeDirection(char c)
        {
            switch (c)
            {
            case '\\':
                switch (this.movingDirection)
                {
                case Direction.LEFT:
                    movingDirection = Direction.UP;
                    break;

                case Direction.RIGHT:
                    movingDirection = Direction.DOWN;
                    break;

                case Direction.UP:
                    movingDirection = Direction.LEFT;
                    break;

                case Direction.DOWN:
                    movingDirection = Direction.RIGHT;
                    break;
                }
                break;

            case '/':
                switch (this.movingDirection)
                {
                case Direction.LEFT:
                    movingDirection = Direction.DOWN;
                    break;

                case Direction.RIGHT:
                    movingDirection = Direction.UP;
                    break;

                case Direction.UP:
                    movingDirection = Direction.RIGHT;
                    break;

                case Direction.DOWN:
                    movingDirection = Direction.LEFT;
                    break;
                }
                break;

            case '+':

                switch (nextTurn)
                {
                case TurnDirection.LEFT:
                    movingDirection = (Direction)mod(((int)movingDirection - 1), 4);
                    if ((int)movingDirection == -1)
                    {
                        Console.Write("?");
                    }
                    break;

                case TurnDirection.RIGHT:
                    movingDirection = (Direction)mod(((int)movingDirection + 1), 4);
                    break;

                default:
                    break;
                }
                nextTurn = (TurnDirection)((int)(nextTurn + 1) % 3);
                break;
            }
            UpdateVelocity();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="destination">The position of the destination relative to the turning point</param>
        /// <param name="radius">The radius of the turning circle</param>
        /// <param name="turnDirection">If the turn is clockwise or anti clockwise</param>
        /// <returns></returns>
        public Angle DetermineTurnEnd(Vector destination, double radius, TurnDirection turnDirection)
        {
            Angle angleTowardsDestination = new Angle(destination);

            Angle tangentAngles = new Angle(Math.Acos(radius / destination.Length));

            Angle desiredEndPoint;
            if (turnDirection == TurnDirection.Clockwise)
            {
                desiredEndPoint = angleTowardsDestination + tangentAngles;
            }
            else
            {
                desiredEndPoint = angleTowardsDestination - tangentAngles;
            }
            desiredEndPoint.ReduceAngle();
            return desiredEndPoint;
        }
Exemple #43
0
        public void Turn(TurnDirection turn)
        {
            switch (turn)
            {
                case TurnDirection.Left:
                    Direction = TileDirectionUtil.TurnLeft(Direction);
                    break;

                case TurnDirection.Right:
                    Direction = TileDirectionUtil.TurnRight(Direction);
                    break;
            }
        }
Exemple #44
0
 public Robot(TileCoordinates position, FlatDirection direction, string colour, bool immobile, bool required, RobotAction initialAction, Vector3 guiColour, TurnDirection turnPreference, Model model, AnimSet animations, SoundSet sounds, Vector3?lightColour, float?lightRadius, RenderPass renderPass, bool castShadows)
 {
     m_colour         = colour;
     m_immobile       = immobile;
     m_required       = required;
     m_spawnAction    = initialAction;
     m_spawnPosition  = position;
     m_spawnDirection = direction;
     m_turnPreference = turnPreference;
     if (lightColour.HasValue && lightRadius.HasValue)
     {
         m_lightColour = lightColour.Value;
         m_light       = new PointLight(Vector3.Zero, lightColour.Value, lightRadius.Value);
     }
     m_modelInstance = new ModelInstance(model, Matrix4.Identity);
     m_animations    = animations;
     m_sounds        = sounds;
     m_guiColour     = guiColour;
     m_renderPass    = renderPass;
     m_castShadows   = castShadows;
 }
Exemple #45
0
    public void GenerateNextBox(bool fade = true)
    {
        count++;

        Transform next = null;

        float width  = 1;
        float length = 1;

        if (count < nextCount)
        {
            next = Instantiate(PFB_BOX);

            if (lastBox.tag == "Box")
            {
                width = 1;

                float r = Random.Range(0f, 1f);

                if (r < rateShort)
                {
                    length = 1.5f;
                    next.GetComponent <SCR_Box>().SetLength(BoxLength.SHORT);
                }
                else if (r < rateShort + rateMedium)
                {
                    length = 2.5f;
                    next.GetComponent <SCR_Box>().SetLength(BoxLength.MEDIUM);
                }
                else
                {
                    length = 3.5f;
                    next.GetComponent <SCR_Box>().SetLength(BoxLength.LONG);
                }

                key++;

                float shortRange    = 0.666f;
                float shortMin      = 0.333f;
                float shortAccelRev = 10.0f;
                rateShort = (key * shortRange) / (key + shortAccelRev) + shortMin;

                /*
                 * float mediumRange = 0.166f;
                 * float mediumMin = 0.333f;
                 * float mediumAccelRev = 50.0f;
                 * rateMedium = (key * mediumRange) / (key + mediumAccelRev) + mediumMin;
                 */

                Time.timeScale = (key * speedRange) / (key + speedAccelRev) + speedMin;
            }

            if (lastBox.tag == "Corner")
            {
                width  = 1;
                length = 2.2f;
                next.GetComponent <SCR_Box>().SetLength(BoxLength.MEDIUM);
            }
        }
        else
        {
            next = Instantiate(PFB_CORNER);

            /*
             * float r = Random.Range(0f, 1f);
             * if (r < 0.5f) {
             *      next.GetComponent<SCR_Corner>().turnDirection = TurnDirection.LEFT;
             * }
             * else {
             *      next.GetComponent<SCR_Corner>().turnDirection = TurnDirection.RIGHT;
             * }
             */
            next.GetComponent <SCR_Corner>().turnDirection = nextTurnDirection;
            if (nextTurnDirection == TurnDirection.LEFT)
            {
                nextTurnDirection = TurnDirection.RIGHT;
            }
            else
            {
                nextTurnDirection = TurnDirection.LEFT;
            }

            width  = 1;
            length = 2.2f;
            next.GetComponent <SCR_Box>().SetLength(BoxLength.MEDIUM);

            count = 0;

            float r = Random.Range(0f, 1f);
            if (r < 0.3f)
            {
                nextCount = 2;
            }
            else
            {
                nextCount = Random.Range(3, 7);
            }
        }

        float x = lastBox.position.x;
        float y = lastBox.position.y;
        float z = lastBox.position.z;

        SCR_Box scrBoxLast = lastBox.GetComponent <SCR_Box>();
        SCR_Box scrBoxNext = next.GetComponent <SCR_Box>();

        if (lastBox.tag == "Box")
        {
            WallDirection wallDirection = scrBoxLast.wallDirection;

            if (wallDirection == WallDirection.NONE)
            {
                wallDirection = savedWallDirection;
            }

            if (wallDirection == WallDirection.NEGATIVE_X)
            {
                next.localScale = new Vector3(length, PFB_BOX.localScale.y, width);

                x += lastBox.localScale.x * 0.5f + next.localScale.x * 0.5f;
                y += PFB_BOX.localScale.y;
            }

            if (wallDirection == WallDirection.POSITIVE_X)
            {
                next.localScale = new Vector3(length, PFB_BOX.localScale.y, width);

                x -= lastBox.localScale.x * 0.5f + next.localScale.x * 0.5f;
                y += PFB_BOX.localScale.y;
            }

            if (wallDirection == WallDirection.NEGATIVE_Z)
            {
                next.localScale = new Vector3(width, PFB_BOX.localScale.y, length);

                y += PFB_BOX.localScale.y;
                z += lastBox.localScale.z * 0.5f + next.localScale.z * 0.5f;
            }

            if (wallDirection == WallDirection.POSITIVE_Z)
            {
                next.localScale = new Vector3(width, PFB_BOX.localScale.y, length);

                y += PFB_BOX.localScale.y;
                z -= lastBox.localScale.z * 0.5f + next.localScale.z * 0.5f;
            }

            scrBoxNext.wallDirection = wallDirection;
        }

        if (lastBox.tag == "Corner")
        {
            SCR_Corner scrCorner = lastBox.GetComponent <SCR_Corner>();

            scrBoxNext.wallDirection = WallDirection.NONE;

            Transform cylinder = Instantiate(PFB_CYLINDER);
            scrBoxNext.cylinder = cylinder;

            if (scrBoxLast.wallDirection == WallDirection.NEGATIVE_X)
            {
                next.localScale = new Vector3(width, PFB_BOX.localScale.y, length);

                x += lastBox.localScale.x * 0.5f;

                if (scrCorner.turnDirection == TurnDirection.LEFT)
                {
                    z += next.localScale.z * 0.5f;
                    savedWallDirection = WallDirection.NEGATIVE_Z;
                }

                if (scrCorner.turnDirection == TurnDirection.RIGHT)
                {
                    z -= next.localScale.z * 0.5f;
                    savedWallDirection = WallDirection.POSITIVE_Z;
                }

                cylinder.position = new Vector3(lastBox.position.x + lastBox.localScale.x * 0.5f, lastBox.position.y, lastBox.position.z);
            }

            if (scrBoxLast.wallDirection == WallDirection.POSITIVE_X)
            {
                next.localScale = new Vector3(width, PFB_BOX.localScale.y, length);

                x -= lastBox.localScale.x * 0.5f;

                if (scrCorner.turnDirection == TurnDirection.LEFT)
                {
                    z -= next.localScale.z * 0.5f;
                    savedWallDirection = WallDirection.POSITIVE_Z;
                }

                if (scrCorner.turnDirection == TurnDirection.RIGHT)
                {
                    z += next.localScale.z * 0.5f;
                    savedWallDirection = WallDirection.NEGATIVE_Z;
                }

                cylinder.position = new Vector3(lastBox.position.x - lastBox.localScale.x * 0.5f, lastBox.position.y, lastBox.position.z);
            }

            if (scrBoxLast.wallDirection == WallDirection.NEGATIVE_Z)
            {
                next.localScale = new Vector3(length, PFB_BOX.localScale.y, width);

                z += lastBox.localScale.z * 0.5f;

                if (scrCorner.turnDirection == TurnDirection.LEFT)
                {
                    x -= next.localScale.x * 0.5f;
                    savedWallDirection = WallDirection.POSITIVE_X;
                }

                if (scrCorner.turnDirection == TurnDirection.RIGHT)
                {
                    x += next.localScale.x * 0.5f;
                    savedWallDirection = WallDirection.NEGATIVE_X;
                }

                cylinder.position = new Vector3(lastBox.position.x, lastBox.position.y, lastBox.position.z + lastBox.localScale.z * 0.5f);
            }

            if (scrBoxLast.wallDirection == WallDirection.POSITIVE_Z)
            {
                next.localScale = new Vector3(length, PFB_BOX.localScale.y, width);

                z -= lastBox.localScale.z * 0.5f;

                if (scrCorner.turnDirection == TurnDirection.LEFT)
                {
                    x += next.localScale.x * 0.5f;
                    savedWallDirection = WallDirection.NEGATIVE_X;
                }

                if (scrCorner.turnDirection == TurnDirection.RIGHT)
                {
                    x -= next.localScale.x * 0.5f;
                    savedWallDirection = WallDirection.POSITIVE_X;
                }

                cylinder.position = new Vector3(lastBox.position.x, lastBox.position.y, lastBox.position.z - lastBox.localScale.z * 0.5f);
            }
        }

        next.position = new Vector3(x, y, z);

        //if (fade) {
        //iTween.FadeFrom(next.gameObject, iTween.Hash("alpha", 0, "time", 0.5f));
        //}

        scrBoxNext.GenerateGem();

        lastBox = next;
    }