Ejemplo n.º 1
0
        public static BotPosition[] Move(BotPosition bot, Motion motion, Turn turn, int turns)
        {
            List <BotPosition> moves = new List <BotPosition>(turns);

            if (turns > 1)
            {
                var arr = BotPosition.Move(bot, motion, turn, turns - 1);
                moves.AddRange(arr);
                bot = arr[turns - 2];
            }
            double velocity = bot.Velocity;
            double heading  = bot.Heading;

            switch (motion)
            {
            case Motion.Reverse:
                if (velocity >= Rules.DECELERATION)
                {
                    velocity = velocity - Rules.DECELERATION;
                }
                else if (velocity > 0)
                {
                    velocity = 0;
                }
                else if (velocity * -1 + Rules.ACCELERATION >= Rules.MAX_VELOCITY)
                {
                    velocity = -1 * Rules.MAX_VELOCITY;
                }
                else
                {
                    velocity = velocity - Rules.ACCELERATION;
                }
                break;

            case Motion.Accelerate:
                if (velocity + Rules.ACCELERATION >= Rules.MAX_VELOCITY)
                {
                    velocity = Rules.MAX_VELOCITY;
                }
                else
                {
                    velocity = velocity + Rules.ACCELERATION;
                }
                break;
            }
            switch (turn)
            {
            case Turn.TurnLeft:
                if (motion == Motion.Reverse)
                {
                    heading = heading + Rules.GetTurnRate(Math.Abs(velocity));
                }
                else
                {
                    heading = heading - Rules.GetTurnRate(Math.Abs(velocity));
                }
                break;

            case Turn.TurnRight:
                if (motion == Motion.Reverse)
                {
                    heading = heading - Rules.GetTurnRate(Math.Abs(velocity));
                }
                else
                {
                    heading = heading + Rules.GetTurnRate(Math.Abs(velocity));
                }
                break;
            }
            moves.Add(new BotPosition(bot.Location.VectorProjection(heading, velocity), heading, velocity));
            return(moves.ToArray());
        }
Ejemplo n.º 2
0
 public static BotPosition[] Move(BotPosition bot, Motion motion, Turn turn)
 {
     return(BotPosition.Move(bot, motion, turn, 1));
 }