Пример #1
0
        public string GetNextMove(State state, Countdown countdown)
        {
            if (state.RoundType < 0)
            {
                return(CommandHelper.SelectHero(HeroType.Valkyrie));
            }

            var heroInfo = state.GetMy(UnitType.Hero).First();

            if (!ReadyToAttack(heroInfo.Pos))
            {
                return(GotoPosition());
            }

            var unitsInRange = state.GetHis();
            var unitToAttack = unitsInRange.Where(u => u.Pos.InRadiusTo(heroInfo.Pos, heroInfo.AttackRange))
                               .OrderBy(u => u.Health)
                               .FirstOrDefault();

            if (unitToAttack != null)
            {
                return(CommandHelper.Attack(unitToAttack));
            }
            return(CommandHelper.Wait());
        }
        public override string GetNextMove(State state, Countdown countdown)
        {
            var myHero     = state.GetMy(UnitType.Hero).First(h => h.HeroType == heroType);
            var unitToDeny = GetUnitToDeny(state);

            if (unitToDeny != null)
            {
                return(Deny(unitToDeny));
            }

            Logger.LogDebug($"Hero {myHero.Pos}");
            var closestToEnemyUnit = state.GetMy()
                                     .Where(u => u.UnitType != UnitType.Hero)
                                     .OrderBy(u => u.Pos.DistTo(enemyTower))
                                     .First();

            Logger.LogDebug($"closestToEnemyUnit {closestToEnemyUnit.Pos}");

            var heroDistToTower = myHero.Pos.DistTo(enemyTower);
            var unitDistToTower = closestToEnemyUnit.Pos.DistTo(enemyTower);

            Logger.LogDebug($"{heroDistToTower} < {unitDistToTower}");
            if (heroDistToTower < unitDistToTower)
            {
                return(Move(closestToEnemyUnit.Pos + stepToBase));
            }

            if (myHero.ItemsOwned < 4)
            {
                var itemToBy = state.InitData.Items.Where(i => i.Damage != 0)
                               .OrderByDescending(i => i.Damage)
                               .FirstOrDefault(i => i.ItemCost <= state.Gold);
                if (itemToBy != null)
                {
                    return(CommandHelper.Buy(itemToBy));
                }
            }

            if (state.GetHis().Any(u => myHero.CanAttack(u)))
            {
                var unitToAttack = state.GetHis(UnitType.Unit)
                                   .Where(u => myHero.CanAttack(u))
                                   .OrderBy(u => u.UnitType)
//                    .ThenBy(u => u.Health)
                                   .FirstOrDefault();
                if (unitToAttack != null)
                {
                    return(CommandHelper.Attack(unitToAttack));
                }
            }

            return(Move(closestToEnemyUnit.Pos + stepToBase));
        }
 private string Deny(Unit unitToDeny)
 {
     return(CommandHelper.Attack(unitToDeny));
 }