Ejemplo n.º 1
0
        public static void UpdateBot(Bot bot)
        {
            bot.Orientation = AngleHelper.NormaliseAngle(bot.Orientation + AngleHelper.IntToAngle(bot.Memory[(int)MemoryAddresses.TurnRight] - bot.Memory[(int)MemoryAddresses.TurnLeft]));

            // Right and down are positive x and y respectively
            var netForce = new Vector2(
                bot.GetFromMemory(MemoryAddresses.MoveUp) - bot.GetFromMemory(MemoryAddresses.MoveDown),
                bot.GetFromMemory(MemoryAddresses.MoveRight) - bot.GetFromMemory(MemoryAddresses.MoveLeft));

            var rotation = Matrix3x2.CreateRotation(bot.Orientation);

            bot.Force += Vector2.Transform(netForce, rotation);
        }
Ejemplo n.º 2
0
        public void IntToAngleScalesCorrectly()
        {
            const float FullAngle    = 2 * (float)Math.PI;
            const int   FullAngleInt = 1000;

            var testAngle1 = AngleHelper.IntToAngle(FullAngleInt);
            var testAngle2 = AngleHelper.IntToAngle(FullAngleInt / 2);
            var testAngle3 = AngleHelper.IntToAngle(FullAngleInt / 3);

            testAngle1.Should().BeApproximately(FullAngle, AngleTolerance);
            testAngle2.Should().BeApproximately(FullAngle / 2, AngleTolerance);
            testAngle3.Should().BeApproximately(FullAngle / 3, AngleTolerance);
        }
Ejemplo n.º 3
0
        public void UpdateBotSetsRotation()
        {
            const int turnLeft  = 100;
            const int turnRight = 350;

            var bot = new Bot
            {
                Orientation = 0
            };

            bot.SetMemory(MemoryAddresses.TurnLeft, turnLeft);
            bot.SetMemory(MemoryAddresses.TurnRight, turnRight);

            RuntimeEngine.UpdateBot(bot);

            bot.Orientation.Should().BeApproximately(AngleHelper.IntToAngle(turnRight - turnLeft), 3);
        }