Beispiel #1
0
        public override ITurnAction Update(IBot ownBot, IBattlefield battlefield)
        {
            var enemies = battlefield.Bots.Except(new[] { ownBot });

            if (ownBot.AvailableWeapons.Count == 1)
            {
                var closestWeapon = battlefield.Weapons.OrderBy(ownBot.DistanceTo).First();
                return(ownBot.DistanceTo(closestWeapon) < ownBot.Radius
                    ? TurnAction.PickUpWeapon()
                    : TurnAction.MoveTowards(closestWeapon));
            }

            if (enemies.Any())
            {
                var closestEnemy = enemies.OrderBy(ownBot.DistanceTo).First();
                if (ownBot.EquippedWeapon.Ammunition.Remaining > 0)
                {
                    return(ownBot.DistanceTo(closestEnemy) < ownBot.EquippedWeapon.MaxRange / 2
                        ? TurnAction.ShootAt(closestEnemy)
                        : TurnAction.MoveTowards(closestEnemy));
                }

                var closestWeapon = battlefield.Weapons.OrderBy(ownBot.DistanceTo).First();
                return(ownBot.DistanceTo(closestWeapon) < ownBot.Radius
                    ? TurnAction.PickUpWeapon()
                    : TurnAction.MoveTowards(closestWeapon));
            }
            return(TurnAction.Idle);
        }
Beispiel #2
0
        public override ITurnAction Update(IBot ownBot, IBattlefield battlefield)
        {
            if (ownBot.EquippedWeapon.Ammunition.Remaining == 0)
            {
                var weapon = battlefield.Weapons.OrderBy(a => a.DistanceTo(ownBot)).FirstOrDefault();
                if (weapon != null)
                {
                    return(ownBot.DistanceTo(weapon) > ownBot.Radius
                        ? TurnAction.MoveTowards(weapon)
                        : TurnAction.PickUpWeapon());
                }
            }

            if (ownBot.HitPoints.Percent < 30)
            {
                if (ownBot.HasResource)
                {
                    return(TurnAction.DropDownResource());
                }
                return(TurnAction.MoveTowards(battlefield.Hospitals.First()));
            }

            if (ownBot.HasResource)
            {
                return(ownBot.DistanceTo(ownBot.Home) > ownBot.Radius
                    ? TurnAction.MoveTowards(ownBot.Home)
                    : TurnAction.DropDownResource());
            }

            var target = battlefield.Bots.Except(new[] { ownBot })
                         .Where(b => b.HasResource)
                         .OrderBy(b => b.DistanceTo(ownBot))
                         .FirstOrDefault();

            if (target != null)
            {
                return(ownBot.DistanceTo(target) < ownBot.EquippedWeapon.MaxRange
                    ? TurnAction.ShootAt(target)
                    : TurnAction.MoveTowards(target));
            }

            if (battlefield.Resources.Any())
            {
                var resource = battlefield.Resources.OrderBy(r => r.DistanceTo(ownBot)).First();
                if (ownBot.DistanceTo(resource) < ownBot.Radius)
                {
                    return(TurnAction.PickUpResource());
                }
                return(TurnAction.MoveTowards(resource.Position));
            }

            return(TurnAction.Idle);
        }
Beispiel #3
0
        private static ITurnAction GetResource(IBot ownBot, IBattlefield battlefield)
        {
            var closestResource = battlefield.Resources.OrderBy(ownBot.DistanceTo).First();

            return(ownBot.DistanceTo(closestResource) < ownBot.Radius
                ? TurnAction.PickUpResource()
                : TurnAction.MoveTowards(closestResource));
        }
Beispiel #4
0
        public override ITurnAction Update(IBot ownBot, IBattlefield battlefield)
        {
            if (ownBot.HasResource)
            {
                return(ownBot.DistanceTo(ownBot.Home) > ownBot.Radius
                    ? TurnAction.MoveTowards(ownBot.Home)
                    : TurnAction.DropDownResource());
            }

            if (battlefield.Resources.Any())
            {
                var resource = battlefield.Resources.OrderBy(r => r.DistanceTo(ownBot)).First();
                return(ownBot.DistanceTo(resource) < ownBot.Radius
                    ? TurnAction.PickUpResource()
                    : TurnAction.MoveTowards(resource.Position));
            }

            return(TurnAction.Idle);
        }
Beispiel #5
0
        public override ITurnAction Update(IBot ownBot, IBattlefield battlefield)
        {
            var         maxRange     = ownBot.EquippedWeapon.MaxRange;
            IGameObject closestEnemy = battlefield.Bots.Except(new[] { ownBot }).OrderBy(ownBot.DistanceTo).FirstOrDefault();

            if (closestEnemy != null && ownBot.DistanceTo(closestEnemy) < maxRange)
            {
                return(TurnAction.ShootAt(closestEnemy));
            }

            if (ownBot.HasResource)
            {
                return(GoHomeWithResource(ownBot));
            }
            else
            {
                return(GetResource(ownBot, battlefield));
            }
            //return TurnAction.Idle;
        }
Beispiel #6
0
 private ITurnAction BaseResource(IBot ownBot) =>
 ownBot.DistanceTo(ownBot.Home) < ownBot.Radius
         ? TurnAction.DropDownResource()
         : TurnAction.MoveTowards(ownBot.Home);
Beispiel #7
0
 private ITurnAction GoHomeWithResource(IBot ownBot)
 {
     return(ownBot.DistanceTo(ownBot.Home) < (ownBot.Radius) ? TurnAction.DropDownResource() : TurnAction.MoveTowards(ownBot.Home));
 }
Beispiel #8
0
        public override ITurnAction Update(IBot ownBot, IBattlefield battlefield)
        {
            if (!Corners.Any())
            {
                Corners.Add(new Point(10, 10));
                Corners.Add(new Point(10, battlefield.Height - 10));
                Corners.Add(new Point(battlefield.Width - 10, battlefield.Height - 10));
                Corners.Add(new Point(battlefield.Width - 10, 10));
            }

            if (ownBot.EquippedWeapon.Ammunition.Remaining == 0)
            {
                var weapon = battlefield.Weapons.OrderBy(a => a.DistanceTo(ownBot)).FirstOrDefault();
                if (weapon != null)
                {
                    return(ownBot.DistanceTo(weapon) > ownBot.Radius
                        ? TurnAction.MoveTowards(weapon)
                        : TurnAction.PickUpWeapon());
                }
            }

            if (ownBot.HitPoints.Percent < 50)
            {
                if (ownBot.HasResource)
                {
                    return(TurnAction.DropDownResource());
                }
                var firstAidKit = battlefield.FirstAidKits.OrderBy(f => ownBot.DistanceTo(f)).FirstOrDefault();
                if (firstAidKit != null)
                {
                    if (ownBot.DistanceTo(firstAidKit) < ownBot.Radius)
                    {
                        return(TurnAction.PickUpFirstAidKit());
                    }
                    return(TurnAction.MoveTowards(firstAidKit.Position));
                }
            }

            if (ownBot.HasResource)
            {
                return(ownBot.DistanceTo(ownBot.Home) > ownBot.Radius
                    ? TurnAction.MoveTowards(ownBot.Home)
                    : TurnAction.DropDownResource());
            }

            var target = battlefield.Bots.Except(new[] { ownBot })
                         .Where(b => b.HasResource)
                         .OrderBy(b => b.DistanceTo(ownBot))
                         .FirstOrDefault();

            if (target != null)
            {
                return(ownBot.DistanceTo(target) < ownBot.EquippedWeapon.MaxRange
                    ? TurnAction.ShootAt(target)
                    : TurnAction.MoveTowards(target));
            }

            if (myAttacker != null)
            {
                if (ownBot.HasResource)
                {
                    return(TurnAction.DropDownResource());
                }

                if (battlefield.Bots.Contains(myAttacker))
                {
                    return(ownBot.DistanceTo(myAttacker) < ownBot.EquippedWeapon.MaxRange
                        ? TurnAction.ShootAt(myAttacker)
                        : TurnAction.MoveTowards(myAttacker));
                }

                myAttacker = null;
            }

            if (battlefield.Resources.Any())
            {
                var resource = battlefield.Resources.OrderBy(r => r.DistanceTo(ownBot)).First();
                if (ownBot.DistanceTo(resource) < ownBot.Radius)
                {
                    return(TurnAction.PickUpResource());
                }
                return(TurnAction.MoveTowards(resource.Position));
            }

            return(TurnAction.Idle);
        }