示例#1
0
        // Doit d'abord vérifier si peut acheter
        internal string WhatToBuy_Amelioration(IPlayer playerInfo)
        {
            string AmeliorationEnCours = Amelioration[_numAmelioration];

            if (AmeliorationEnCours[1] == 'C')
            {
                _numAmelioration++;
                return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
            }
            if (AmeliorationEnCours[1] == 'S')
            {
                _numAmelioration++;
                return(AIHelper.CreateUpgradeAction(UpgradeType.CollectingSpeed));
            }
            if (AmeliorationEnCours[1] == 'D')
            {
                _numAmelioration++;
                return(AIHelper.CreateUpgradeAction(UpgradeType.Defence));
            }
            if (AmeliorationEnCours[1] == 'A')
            {
                _numAmelioration++;
                return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
            }
            if (AmeliorationEnCours[1] == 'H')
            {
                _numAmelioration++;
                return(AIHelper.CreateUpgradeAction(UpgradeType.MaximumHealth));
            }
            return("");
        }
示例#2
0
        public string returnMoveAction(List <Point> ressourcePositions, IPlayer playerInfor, Map map)
        {
            var houseDistance = calculateHouseDistance(housePosition, playerInfor);

            Console.WriteLine("Capacity: " + playerInfor.CarriedResources);

            if (ressourcePositions.Count == 0)
            {
                return(moveToHouse(houseDistance, playerInfor, map));
            }
            var distance = calculateTileDistance(ressourcePositions, playerInfor);

            if (playerInfor.CarriedResources == 500)//playerInfor.CarryingCapacity)
            {
                isPassed = false;
                return(moveToHouse(houseDistance, playerInfor, map));
            }

            if (playerInfor.Position.X == searchMap.housePosition.X && playerInfor.Position.Y == searchMap.housePosition.Y && !isPassed)
            {
                isPassed = true;
                return(AIHelper.CreateUpgradeAction(UpgradeType.CollectingSpeed));
            }
            isPassed = false;
            return(moveToRessource(distance, ressourcePositions, playerInfor, map));
        }
示例#3
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);
        }
 public string Upgrade(int upgradeType)
 {
     if (PlayerInfo.Position != PlayerInfo.HouseLocation)
     {
         return(MovementActions.MoveTo(GameMap, PlayerInfo.HouseLocation - PlayerInfo.Position));
     }
     else
     {
         return(AIHelper.CreateUpgradeAction((UpgradeType)upgradeType));
     }
 }
示例#5
0
    protected override string UpdateState()
    {
        Console.WriteLine("Upgrade");


        int collectingLevel = brain.playerInfo.GetUpgradeLevel(UpgradeType.CollectingSpeed);

        if (brain.playerInfo.Position == brain.playerInfo.HouseLocation && collectingLevel != 5)
        {
            brain.UpgradeGear(UpgradeType.CollectingSpeed);
            ExitCurrentState();
            Console.WriteLine("Buying");

            return(AIHelper.CreateUpgradeAction(UpgradeType.CollectingSpeed));
        }
        return(GoTo(brain.playerInfo.HouseLocation));
    }
示例#6
0
文件: Bot.cs 项目: LHGames-2018/XSF
 internal string getType(int u)
 {
     if (u == 0)
     {
         return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
     }
     if (u == 1)
     {
         return(AIHelper.CreateUpgradeAction(UpgradeType.CollectingSpeed));
     }
     if (u == 2)
     {
         return(AIHelper.CreateUpgradeAction(UpgradeType.Defence));
     }
     if (u == 3)
     {
         return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
     }
     if (u == 4)
     {
         return(AIHelper.CreateUpgradeAction(UpgradeType.MaximumHealth));
     }
     return("");
 }
示例#7
0
 public override string Execute()
 {
     return(AIHelper.CreateUpgradeAction(_upgradeList.Pop()));
 }
示例#8
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());
            }
        }
示例#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)
        {
            Console.WriteLine("My pos = " + PlayerInfo.Position.ToString());
            Console.WriteLine("House  = " + PlayerInfo.HouseLocation.ToString());
            Console.WriteLine("Total  = " + PlayerInfo.TotalResources.ToString());
            Console.WriteLine("Collect= " + PlayerInfo.CollectingSpeed.ToString());
            Console.WriteLine("Carryin= " + PlayerInfo.CarryingCapacity.ToString());
            Console.WriteLine("Atk    = " + PlayerInfo.AttackPower.ToString());
            Console.WriteLine("Def    = " + PlayerInfo.Defence.ToString());
            Console.WriteLine("Health = " + PlayerInfo.Health.ToString());
            Console.WriteLine("Max Hea= " + PlayerInfo.MaxHealth.ToString());
            Console.WriteLine("C1     = " + (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                                             PlayerInfo.TotalResources >= 10000 &&
                                             PlayerInfo.CollectingSpeed == 1).ToString());
            Console.WriteLine("C2     = " + (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                                             PlayerInfo.TotalResources >= 10000 &&
                                             PlayerInfo.CarryingCapacity == 1000).ToString());


            //Bypass upgrade
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 10000 &&
                PlayerInfo.CarryingCapacity == 1000)
            {
                Console.WriteLine("Buying a Carrying Capacity");
                return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
            }
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 10000 &&
                PlayerInfo.CarryingCapacity == 1250)
            {
                Console.WriteLine("Buying a Carrying Capacity");
                return(AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity));
            }
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 10000 &&
                PlayerInfo.AttackPower == 1)
            {
                Console.WriteLine("Buying a Attack");
                return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
            }
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 10000 &&
                PlayerInfo.Defence == 1)
            {
                Console.WriteLine("Buying a Defence");
                return(AIHelper.CreateUpgradeAction(UpgradeType.Defence));
            }
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 15000 &&
                PlayerInfo.AttackPower == 2)
            {
                Console.WriteLine("Buying a Attack");
                return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
            }
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 15000 &&
                PlayerInfo.Defence == 2)
            {
                Console.WriteLine("Buying a Defence");
                return(AIHelper.CreateUpgradeAction(UpgradeType.Defence));
            }
            if (PlayerInfo.Position == PlayerInfo.HouseLocation &&
                PlayerInfo.TotalResources >= 25000 &&
                PlayerInfo.AttackPower == 4)
            {
                Console.WriteLine("Buying a Attack");
                return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
            }

            //fin des upgrades


            //update map of the world
            worldMap.UpdateMap(map.GetVisibleTiles());
            //worldMap.UpdateOtherPLayerMap(gameInfo.OtherPlayers);
            StrategyManager.PickStrategy(PlayerInfo, visiblePlayers, worldMap);
            return(StrategyManager.currentStrategy.GetNextMove(PlayerInfo, visiblePlayers, worldMap));

            /*string action = null;
             *
             * Console.WriteLine("Collect= " + PlayerInfo.CollectingSpeed.ToString());
             * Console.WriteLine("Carryin= " + PlayerInfo.CarryingCapacity.ToString());
             * =======
             *
             *
             * //Bypass upgrade
             * if (PlayerInfo.Position == PlayerInfo.HouseLocation && !alreadyTriedToBuy)
             * {
             *  Console.WriteLine("Buying a Carrying Capacity");
             *  alreadyTriedToBuy = true;
             *  return AIHelper.CreateUpgradeAction(UpgradeType.CarryingCapacity);
             * }
             * if (PlayerInfo.Position != PlayerInfo.HouseLocation)
             * {
             *  alreadyTriedToBuy = false;
             * }
             *
             *
             *
             * //update map of the world
             * worldMap.UpdateMap(map.GetVisibleTiles());
             * //worldMap.UpdateOtherPLayerMap(gameInfo.OtherPlayers);
             * StrategyManager.PickStrategy();
             * return StrategyManager.currentStrategy.GetNextMove(PlayerInfo, visiblePlayers, worldMap);
             *
             * /*string action = null;
             *
             * string action = null;
             * while (action == null)
             * {
             *  if (currentAction == null)
             *  {
             *      currentAction = strategy.NextAction(worldMap, PlayerInfo);
             *      if (currentAction == null)
             *      {
             *          break;
             *      }
             *      //log(currentAction.ToString());
             *  }
             *  action = currentAction.NextAction(worldMap, PlayerInfo);
             *  if (action == null)
             *  {
             *      currentAction = null;
             *  }
             * }
             *
             * return action;*/
        }
示例#10
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)
        {
            worldMap = WorldMap.ReadMap();
            if (worldMap == null || worldMap.HomePosition != PlayerInfo.HouseLocation)
            {
                worldMap = new WorldMap();
            }
            worldMap.UpdateWorldMap(map);
            worldMap.HomePosition = PlayerInfo.HouseLocation;
            WorldMap.WriteMap(worldMap);
            this.astarService     = new AStarAlgo(worldMap);
            this.ressourcePlaner  = new RessourcePlaner(worldMap, PlayerInfo, astarService);
            this.navigationHelper = new NavigationHelper(PlayerInfo, astarService);
            this.manathan         = new Manathan();
            this.placePlaner      = new PlacePlaner(map, PlayerInfo, astarService);

            Console.WriteLine("Cash : " + PlayerInfo.TotalResources);

            try
            {
                var best_ressource = ressourcePlaner.GetBestRessourcePath();
                //var best_place_for_shop = placePlaner.GetBestPlacePath(TileContent.Shop);
                //	10000	15000	25000	50000	100000
                if (PlayerInfo.Position == PlayerInfo.HouseLocation)
                {
                    bool upgrade = false;
                    switch (PlayerInfo.GetUpgradeLevel(UpgradeType.AttackPower))
                    {
                    case 0:
                        if (PlayerInfo.TotalResources >= 10000)
                        {
                            upgrade = true;
                        }
                        break;

                    case 1:
                        if (PlayerInfo.TotalResources >= 15000)
                        {
                            upgrade = true;
                        }
                        break;

                    case 2:
                        if (PlayerInfo.TotalResources >= 25000)
                        {
                            upgrade = true;
                        }
                        break;

                    case 3:
                        if (PlayerInfo.TotalResources >= 50000)
                        {
                            upgrade = true;
                        }
                        break;

                    case 4:
                        if (PlayerInfo.TotalResources >= 100000)
                        {
                            upgrade = true;
                        }
                        break;
                    }
                    if (upgrade)
                    {
                        return(AIHelper.CreateUpgradeAction(UpgradeType.AttackPower));
                    }
                }

                if (PlayerInfo.CarriedResources < PlayerInfo.CarryingCapacity && best_ressource != null)
                {
                    if (best_ressource.Path.Count == 2)
                    {
                        // On est adjacent à la meilleure ressource
                        var direction = astarService.DirectionToward(PlayerInfo.Position, best_ressource.Tile.Position);
                        return(AIHelper.CreateCollectAction(direction));
                    }
                    else if (best_ressource.Path.Count == 1)
                    {
                        // on est dessus
                        var tileToGo = map.GetTile(PlayerInfo.Position.X - 1, PlayerInfo.Position.Y);
                        var action   = navigationHelper.NavigateToNextPosition(tileToGo);
                        return(action);
                    }
                    else
                    {
                        // On est pas rendu
                        return(navigationHelper.NavigateToNextPosition(best_ressource.Path[1]));
                    }
                }
                else
                {
                    // on doit aller à la base
                    var home_tile    = worldMap.GetTile(PlayerInfo.HouseLocation.X, PlayerInfo.HouseLocation.Y);
                    var current_tile = worldMap.GetTile(PlayerInfo.Position.X, PlayerInfo.Position.Y);
                    if (home_tile == null)
                    {
                        var path = manathan.GetManathanPath(current_tile.Position, PlayerInfo.HouseLocation);
                        return(navigationHelper.NavigateToNextPosition(worldMap.GetTile(path[0].X, path[0].Y)));
                    }
                    else
                    {
                        var best_path_to_home = astarService.Run(current_tile, home_tile);

                        if (best_path_to_home == null)
                        {
                            var path = manathan.GetManathanPath(current_tile.Position, PlayerInfo.HouseLocation);
                            return(navigationHelper.NavigateToNextPosition(worldMap.GetTile(path[0].X, path[0].Y)));
                        }
                        // On est pas rendu
                        return(navigationHelper.NavigateToNextPosition(best_path_to_home[1]));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("*** Reset the map! ***");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.InnerException);
                Console.WriteLine("*** inner exception ***");
                Console.WriteLine(e);
                Console.WriteLine("*** exception ***");

                worldMap = new WorldMap();
                worldMap.UpdateWorldMap(map);
                worldMap.HomePosition = PlayerInfo.HouseLocation;
                WorldMap.WriteMap(worldMap);

                return("");
            }

            /*
             *             AStarAlgo astar = new AStarAlgo(map);
             * var result = astar.Run(PlayerInfo.Position, new Point(-4, 21));
             *
             *
             * var data = StorageHelper.Read<TestClass>("Test");
             * Console.WriteLine(data?.Test);
             * //return AIHelper.CreateMoveAction(new Point(_currentDirection, 0)); astar.DirectionToward(PlayerInfo.Position, result[0].Position);
             * return AIHelper.CreateMoveAction(astar.DirectionToward(PlayerInfo.Position, result[0].Position));*/
        }