public void Startup(IAStar astar) { if (astar == null) { Debug.LogError("A* Startup Failed!!! astar was null~"); return; } this.mInvoker = astar; }
internal PlacePlaner(Map map, IPlayer player, IAStar astarService) { this.map = map; this.player = player; this.astarService = astarService; }
public void Initialize(IAStar aStar) { mInvoker = aStar; debugTextPrefab = Resources.Load <GameObject>("Prefabs/AStarDebugItem"); }
public AStar(IAStar <T> map) { this.map = map; }
public NavigationHelper(IPlayer player, IAStar astar) { this.player = player; this.astar = astar; }
/// <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));*/ }
public static IEnumerable <TNode> Search <TNode>(this IAStar <TNode> astar, TNode start, TNode goal) { var closedSet = new HashSet <TNode>(); // nodes already evaluated var openSet = new HashSet <TNode> { start }; // nodes to be evaluated var cameFrom = new Dictionary <TNode, TNode>(); // the map of navigated nodes var g = new Dictionary <TNode, int>(); // g score for each node, cost from start along best path g[start] = 0; var f = new Dictionary <TNode, int>(); // f score for each node, estimated total cost from start to goal f[start] = g[start] + astar.HeuristicCostEstimate(start, goal); while (openSet.Count > 0) { // current is the node in openSet with lowest f score var current = openSet.First(); foreach (var node in openSet) { if (f[node] < f[current]) { current = node; } } // back track and yield path if we have reached the destination); if (current.Equals(goal)) { IList <TNode> path; ReconstructPath(cameFrom, goal, out path); return(path); } openSet.Remove(current); closedSet.Add(current); foreach (var neighbour in astar.GetNeighbourNodes(current)) { if (closedSet.Contains(neighbour)) { continue; } var tentativeG = g[current] + astar.HeuristicCostEstimate(current, neighbour); // TODO distance? if (!openSet.Contains(neighbour) || tentativeG < g[neighbour]) { cameFrom[neighbour] = current; g[neighbour] = tentativeG; f[neighbour] = g[neighbour] + astar.HeuristicCostEstimate(neighbour, goal); if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } } } } return(new TNode[] {}); }
internal RessourcePlaner(WorldMap map, IPlayer player, IAStar astarService) { this.map = map; this.player = player; this.astarService = astarService; }