Ejemplo n.º 1
0
        /// <summary>
        /// Implement your bot here.
        /// </summary>
        /// <param name="map">The gamemap.</param>
        /// <param name="visiblePlayers">Players that are visible to your bot.</param>
        /// <returns>The action you wish to execute.</returns>
        internal string ExecuteTurn(Map map, IEnumerable <IPlayer> visiblePlayers)
        {
            getInterestingObjects(map, PlayerInfo.Position);
            objects.Sort((x, y) => x.priority.CompareTo(y.priority));
            Point nextMove;

            if (PlayerInfo.Position == PlayerInfo.HouseLocation)
            {
                nextMove = new Point();
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.Defence) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.Defence));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.CarryingCapacity) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.AttackPower) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.CarryingCapacity) == 1 && PlayerInfo.TotalResources >= upgrades[1])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
                }
                if (PlayerInfo.GetUpgradeLevel(UpgradeType.CollectingSpeed) == 0 && PlayerInfo.TotalResources >= upgrades[0])
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.CollectingSpeed));
                }
            }

            if (PlayerInfo.TotalResources >= 30000 && !PlayerInfo.CarriedItems.Contains(PurchasableItem.Backpack))
            {
                Point shopLocation = map.GetVisibleTiles().FirstOrDefault(x => x.TileType == TileContent.Shop)?.Position;

                if (shopLocation == null)
                {
                    TileContent tileToTheLeft = map.GetTileAt(PlayerInfo.Position.X - 1, PlayerInfo.Position.Y);
                    nextMove = tileToTheLeft != TileContent.Resource && tileToTheLeft != TileContent.Lava ? new Point(-1, 0) : new Point(0, 1);
                }
                else
                {
                    nextMove = new PathFinder(map, PlayerInfo.Position, shopLocation).FindNextMove();
                }

                if (Point.DistanceSquared(PlayerInfo.Position, shopLocation) == 1)
                {
                    return(AIHelper.CreatePurchaseAction(PurchasableItem.Backpack));
                }
            }
            else if (PlayerInfo.CarriedResources == PlayerInfo.CarryingCapacity || objects.Count == 0)
            {
                nextMove = new PathFinder(map, PlayerInfo.Position, PlayerInfo.HouseLocation).FindNextMove();
            }
            else
            {
                nextMove = new PathFinder(map, PlayerInfo.Position, objects[0].position).FindNextMove();
            }
            Point shouldIStayOrShouldIGoNow = PlayerInfo.Position + nextMove;

            TileContent content = map.GetTileAt(shouldIStayOrShouldIGoNow.X, shouldIStayOrShouldIGoNow.Y);

            switch (content)
            {
            case TileContent.Empty:
            case TileContent.House:
                return(AIHelper.CreateMoveAction(nextMove));

            case TileContent.Resource:
                return(AIHelper.CreateCollectAction(nextMove));

            case TileContent.Wall:
                return(AIHelper.CreateMeleeAttackAction(nextMove));

            case TileContent.Player:
                return(AIHelper.CreateMeleeAttackAction(nextMove));

            default:
                return(AIHelper.CreateEmptyAction());
            }
        }