コード例 #1
0
        internal string GetNextAction(MyMap map, IPlayer PlayerInfo)
        {
            _map        = map;
            _playerInfo = PlayerInfo;

            string action = null;

            for (int i = 0; i < _behaviours.Count; i++)
            {
                if (_behaviours[i].Evaluate())
                {
                    if (_behaviours[i] != _currentBehaviours)
                    {
                        _currentBehaviours?.StateOut();
                        _currentBehaviours = _behaviours[i];
                        _currentBehaviours.StateIn();
                    }

                    action = _currentBehaviours?.Execute();
                    break;
                }
            }

            return(action ?? AIHelper.CreateEmptyAction());
        }
コード例 #2
0
ファイル: Bot.cs プロジェクト: LHGames-2018/LHoes
        private string MineResources(Map map)
        {
            string      action            = "";
            bool        isFull            = PlayerInfo.CarriedResources >= PlayerInfo.CarryingCapacity;
            List <Tile> possibleResources = new List <Tile>();

            foreach (Tile tile in map.GetVisibleTiles())
            {
                if (tile.TileType == TileContent.Resource)
                {
                    possibleResources.Add(tile);
                }
            }

            // Sort resources
            possibleResources.Sort((a, b) => Point.Distance(a.Position, PlayerInfo.Position).CompareTo(Point.Distance(b.Position, PlayerInfo.Position)));

            Point adjacentResource = GetAdjacentResource(map);

            // prioritize this and upgrade
            if (PlayerInfo.Position == PlayerInfo.HouseLocation)
            {
                //int carryingLevel = PlayerInfo.GetUpgradeLevel(UpgradeType.CarryingCapacity);
                int maxHealthLevel = PlayerInfo.GetUpgradeLevel(UpgradeType.MaximumHealth);
                int attackLevel    = PlayerInfo.GetUpgradeLevel(UpgradeType.AttackPower);
                if (attackLevel < 4 && UpgradeCosts[attackLevel + 1] <= PlayerInfo.TotalResources)
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
                }
                else if (maxHealthLevel < 5 && UpgradeCosts[maxHealthLevel + 1] <= PlayerInfo.TotalResources)
                {
                    return(AIHelper.CreateUpgradeAction(UpgradeType.MaximumHealth));
                }
            }

            if (!isFull && adjacentResource == null && possibleResources.Count > 0)
            {
                if (possibleResources.Count > 0)
                {
                    action = GoTo(possibleResources[0].Position, map, true);
                }
                else
                {
                    Console.Out.WriteLine("Oups, no action for resource");
                    action = AIHelper.CreateEmptyAction();
                }
            }
            else if (!isFull && adjacentResource != null)
            {
                action = AIHelper.CreateCollectAction(adjacentResource);
            }
            else if (isFull || possibleResources.Count == 0)
            {
                action = GoTo(PlayerInfo.HouseLocation, map, true);
            }

            return(action);
        }
コード例 #3
0
        /// <summary>
        /// Walk right next to a tile
        /// </summary>
        internal string WalkTowardsTile(Point tilePosition, Map map, bool isReturningHome)
        {
            var deltaX = tilePosition.X - PlayerInfo.Position.X;
            var deltaY = tilePosition.Y - PlayerInfo.Position.Y;

            if (!isReturningHome)
            {
                if (deltaX < 0)
                {
                    deltaX += 1;
                }
                else
                {
                    deltaX -= 1;
                }
            }

            //moving character
            if (deltaX != 0)
            {
                var direction = deltaX > 0 ? 1 : -1; // UGLY
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Wall || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(direction)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Lava || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMoveAction(new Point(0, 1)));
                }
                return(AIHelper.CreateMoveAction(new Point(direction)));
            }

            if (deltaY != 0)
            {
                var direction = deltaY > 0 ? 1 : -1;
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Wall || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMeleeAttackAction(new Point(0, direction)));
                }
                if (map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Lava || map.GetTileAt(PlayerInfo.Position.X + direction, PlayerInfo.Position.Y) ==
                    TileContent.Player)
                {
                    return(AIHelper.CreateMoveAction(new Point(1)));
                }
                return(AIHelper.CreateMoveAction(new Point(0, direction)));
            }

            arrivedAtDestination = true;
            return(AIHelper.CreateEmptyAction());
        }
コード例 #4
0
    protected override string UpdateState()
    {
        Console.WriteLine("Return Home");

        if (brain.playerInfo.Position != brain.playerInfo.HouseLocation)
        {
            return(brain.GetDirection(brain.playerInfo.HouseLocation));
        }
        ExitCurrentState();
        return(AIHelper.CreateEmptyAction());
    }
コード例 #5
0
 protected override string UpdateState()
 {
     Console.WriteLine("Steal");
     if (brain.playerInfo.CarriedResources < brain.playerInfo.CarryingCapacity)
     {
         return(StealthRessource());
     }
     else
     {
         ExitCurrentState();
         return(AIHelper.CreateEmptyAction());
     }
 }
コード例 #6
0
    protected override string UpdateState()
    {
        Console.WriteLine("Combat");

        if (targetPlayer.Health > 0)
        {
            return(AttackPlayer());
        }
        else
        {
            ExitCurrentState();
            return(AIHelper.CreateEmptyAction());
        }
    }
コード例 #7
0
    protected override string UpdateState()
    {
        Console.WriteLine("Mining State");

        //Pas full
        Console.WriteLine(brain.playerInfo.CarriedResources + "/" + brain.playerInfo.CarryingCapacity);
        if (brain.playerInfo.CarriedResources < brain.playerInfo.CarryingCapacity)
        {
            return(GatherRessource());
        }
        else
        {
            ExitCurrentState();
            return(AIHelper.CreateEmptyAction());
        }
    }
コード例 #8
0
        internal string MoveRandomly(Map map)
        {
            if (!moving)
            {
                Random rnd = new Random();
                randomDirection = rnd.Next(1, 5);
                randomDistance  = rnd.Next(1, MAX_RANDOM_DISTANCE);
                moving          = true;

                while (randomDirection == previousDirection)
                {
                    randomDirection = rnd.Next(1, 5);
                }
            }

            if (distanceTravelled >= randomDistance)
            {
                moving            = false;
                distanceTravelled = 0;
            }

            if (moving)
            {
                switch (randomDirection)
                {
                case 1:
                    if (MeleeTargetExists(map, 1, 0))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(1, 0)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(1, 0)));

                case 2:
                    if (MeleeTargetExists(map, -1, 0))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(-1, 0)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(-1, 0)));

                case 3:
                    if (MeleeTargetExists(map, 0, 1))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(0, 1)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(0, 1)));

                case 4:
                    if (MeleeTargetExists(map, 0, -1))
                    {
                        return(AIHelper.CreateMeleeAttackAction(new Point(0, -1)));
                    }
                    return(AIHelper.CreateMoveAction(new Point(0, -1)));
                }

                distanceTravelled++;
            }

            if (distanceTravelled >= randomDistance)
            {
                moving            = false;
                distanceTravelled = 0;
            }

            var data = StorageHelper.Read <TestClass>("Test");

            return(AIHelper.CreateEmptyAction());
        }
コード例 #9
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());
            }
        }
コード例 #10
0
    public override string GetNextMove(IPlayer player, IEnumerable <IPlayer> visiblePlayers, LegacyMap map)
    {
        // Dropper nos ressoruces si on est colles a la maison
        if (Point.DistanceManhatan(player.HouseLocation, player.Position) == 0 && player.CarriedResources > 0)
        {
            return(AIHelper.CreateEmptyAction());
        }

        // Verifier si on doit rentrer pour drop nos ressources
        if (player.CarryingCapacity - player.CarriedResources < 100)
        {
            Move moveTowardsHome = new Move(player, map, player.HouseLocation);
            return(moveTowardsHome.NextAction(map, player));
        }

        // Trouver le filon le plus proche
        Point closestMineralPosition = GetClosestMineralPosition(player, map);

        // Si le filon le plus proche renvoit la maison, ca veut dire quon ne truove rien proche de nous. Nous allons donc aller explorer.
        //if (closestMineralPosition.X == player.HouseLocation.X && closestMineralPosition.Y == player.HouseLocation.Y)
        //{
        //    Random random = new Random();
        //    int randomlyGeneratedNumber = random.Next(1, 3);
        //    if (randomlyGeneratedNumber == 1)
        //    {
        //        Move moveTowardsHome = new Move(player, map, new Point(player.Position.X + 1, player.Position.Y));
        //        return moveTowardsHome.NextAction(map, player);
        //    }
        //    else
        //    {
        //        Move moveTowardsHome = new Move(player, map, new Point(player.Position.X, player.Position.Y -1));
        //        return moveTowardsHome.NextAction(map, player);
        //    }
        //}
        Console.WriteLine("");

        // Sinon, good, on a qqch a miner. On trouve la case a partir de laquelle on va miner
        Point closestMineralAdjacentPosition = GetClosestFreeAdjacentPosition(player, closestMineralPosition, map);

        // Si on est colles au filon, le miner
        if (Point.DistanceManhatan(closestMineralPosition, player.Position) <= 1)
        {
            return(AIHelper.CreateCollectAction(new Point(closestMineralPosition.X - player.Position.X,
                                                          closestMineralPosition.Y - player.Position.Y)));
        }

        // Si aller passer par la maison avant daller au filon ne nous ralenti pas, on va aller a la maison tds
        // Verifier si on doit rentrer pour drop nos ressources
        if ((player.CarriedResources >= 500) &&
            ((player.Position.X <= player.HouseLocation.X && closestMineralAdjacentPosition.X >= player.HouseLocation.X &&
              player.Position.Y <= player.HouseLocation.Y && closestMineralAdjacentPosition.Y >= player.HouseLocation.Y)

             || (player.Position.X <= player.HouseLocation.X && closestMineralAdjacentPosition.X >= player.HouseLocation.X &&
                 player.Position.Y >= player.HouseLocation.Y && closestMineralAdjacentPosition.Y <= player.HouseLocation.Y)

             || (player.Position.X >= player.HouseLocation.X && closestMineralAdjacentPosition.X <= player.HouseLocation.X &&
                 player.Position.Y >= player.HouseLocation.Y && closestMineralAdjacentPosition.Y <= player.HouseLocation.Y)

             || (player.Position.X >= player.HouseLocation.X && closestMineralAdjacentPosition.X <= player.HouseLocation.X &&
                 player.Position.Y <= player.HouseLocation.Y && closestMineralAdjacentPosition.Y >= player.HouseLocation.Y)))
        {
            Move moveTowardsHome = new Move(player, map, player.HouseLocation);
            return(moveTowardsHome.NextAction(map, player));
        }

        // Si on est pas colles, quon rentre pas, aller vers le filon
        Move moveTowardsMineral = new Move(player, map, closestMineralAdjacentPosition);

        return(moveTowardsMineral.NextAction(map, player));
    }