示例#1
0
        private ActionModel GetData(WorldState worldState, int playerIndex)
        {
            var player  = worldState.Players[playerIndex];
            var physics = player.Physics;

            var data = new ActionModel
            {
                PlayerPhysics = player.Physics,
                CurrentBoost  = (int)(player.BoostAmount * 100),
                NearestFull   = worldState.BoostPads.Where(b => b.IsActive && b.IsFullBoost)
                                .Where(b =>
                                       Math.Abs(BotMovementHelper.AngleToTarget(player.Physics, b.Location)) < Math.PI / 2
                                       )
                                .FindNearest(physics.Location),
                NearestNormal = worldState.BoostPads.Where(b => b.IsActive && !b.IsFullBoost)
                                .Where(b =>
                                       Math.Abs(BotMovementHelper.AngleToTarget(player.Physics, b.Location)) < Math.PI / 2
                                       ).FindNearest(physics.Location)
            };

            data.BaseBoostPriority   = 1 - data.CurrentBoost / TargetBoostAmount;
            data.FullBoostPriority   = GetDistancePriority(data.NearestFull, data.PlayerPhysics) * FullBoostMulitplier;
            data.NormalBoostPriority = GetDistancePriority(data.NearestNormal, data.PlayerPhysics);

            return(data);
        }
示例#2
0
        private double GetDistancePriority(BoostPad boostPad, ObjectPhysics playerPhysics)
        {
            if (boostPad == null)
            {
                return(0);
            }

            var playerLocation = playerPhysics.Location;
            var rawDistance    = playerLocation.Distance2d(boostPad.Location);
            var maxDistance    = boostPad.IsFullBoost ? MaxFullDistance : MaxNormalDistance;
            var angleToBoost   = Math.Abs(BotMovementHelper.AngleToTarget(playerPhysics, boostPad.Location));

            return((1 - (rawDistance / maxDistance)) * (1 - (angleToBoost / (Math.PI / 2))));
        }
示例#3
0
        public static IEnumerable <IMicroAction> GetMicroActions(Func <WorldState, int, GoToTargetOptions> tickAction, TimeSpan microSpan)
        {
            return(MicroAction.FrequentAction((worldState, playerIndex) =>
            {
                var options = tickAction(worldState, playerIndex);

                var angle = BotMovementHelper.AngleToTarget(options.PlayerPhysics, options.Target);
                var absAngle = Math.Abs(angle);
                var steeringValue = (float)Math.Max(-1, Math.Min(1, angle));

                var throttle = 1f;
                var applyHandbrake = false;
                var applyBoost = false;

                if (absAngle > 1.8 && options.PlayerPhysics.Velocity.Length() > 10)
                {
                    applyHandbrake = true;
                }
                else if (absAngle > 1.2)
                {
                    throttle = (float)((absAngle - 1.2) * 0.5);
                }

                if (options.UseBoost && absAngle < 1)
                {
                    applyBoost = true;
                }

                return new Controller
                {
                    Steer = steeringValue,
                    Handbrake = applyHandbrake,
                    Throttle = throttle,
                    Boost = applyBoost
                };
            }, 100, microSpan));
        }