public ResourceTileDescriptor GetBestRessourcePath() { var home_tile = map.GetTile(player.HouseLocation.X, player.HouseLocation.Y); var current_tile = map.GetTile(player.Position.X, player.Position.Y); var ressourceTile = map.GetTile(home_tile.Position.X + 4, home_tile.Position.Y - 2); var best_path_to_ressource = astarService.Run(current_tile, ressourceTile); return(new ResourceTileDescriptor() { Path = best_path_to_ressource, Tile = ressourceTile }); }
public List <PlaceTileDescriptor> GetPlacesPaths(TileContent tileContent) { List <Tile> ressourceTiles = GetPlacesTiles(tileContent); Tile currentTile = map.GetTile(player.Position.X, player.Position.Y); List <PlaceTileDescriptor> placeTileDescriptors = new List <PlaceTileDescriptor>(); ressourceTiles.ToList().ForEach(ressourceTile => { List <Tile> calculatedPath = astarService.Run(currentTile, ressourceTile); if (calculatedPath != null && calculatedPath.Count != 0) { PlaceTileDescriptor res = new PlaceTileDescriptor { Tile = ressourceTile, Path = calculatedPath }; placeTileDescriptors.Add(res); } }); return(placeTileDescriptors); }
/// <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));*/ }