public static List <Location> simpleRoute(SquareGrid grid, Location start, Location finish) { List <Location> path = new List <Location>(); AStarSearch astar = new AStarSearch(grid, start, finish); path = astar.ReconstructPath(start, finish, astar.cameFrom); return(path); }
private string doDrone(List <Order> droneOrders) { List <List <Location> > dronePaths = new List <List <Location> >(); foreach (var order in droneOrders) { List <Location> path = new List <Location>(); AStarSearch astar = new AStarSearch(grid, Depot, new Location(order.x, order.y, 0)); path = astar.ReconstructPath(Depot, new Location(order.x, order.y, 0), astar.cameFrom); var returnPath = path; returnPath.Reverse(); path.AddRange(returnPath); dronePaths.Add(path); } return(Drone.droneStatusUpdate(dronePaths, DroneTime)); }
private string doTruck(Location depot, List <Order> truckOrders, Truck truck) { if (truckOrders is null) { return(string.Empty); } if (Settings.TrafficScore != 0) { Truck.adjustTruckSpeed(); } List <List <Location> > truckPaths = new List <List <Location> >(); List <Location> path; AStarSearch astar = new AStarSearch(groundGrid, depot, new Location(truckOrders.First().x, truckOrders.First().y, 0)); path = astar.ReconstructPath(depot, new Location(truckOrders.First().x, truckOrders.First().y, 0), astar.cameFrom); truckPaths.Add(path); truck.currentPosition = new Location(truckOrders.First().x, truckOrders.First().y, 0); var pathLength = path.Count * BaseConstants.PolygonSize; var deliveryTime = pathLength / BaseConstants.TruckSpeed + BaseConstants.DropDeliveryTime; truck.time += deliveryTime; truck.status = Status.OnMission; truck.log.Add(new Log(truck.id, truck.currentPosition, orders.Where(x => (x.x == truck.currentPosition.x && x.y == truck.currentPosition.y)).First().address, truck.time, truck.status, "Delivery finished")); for (int i = 0; i < truckOrders.Count - 1; i++) { if (Settings.TrafficScore != 0) { Truck.adjustTruckSpeed(truck.time); } var start = new Location(truckOrders[i].x, truckOrders[i].y, 0); var deliveryLocation = new Location(truckOrders[i + 1].x, truckOrders[i + 1].y, 0); astar = new AStarSearch(groundGrid, start, deliveryLocation); path = astar.ReconstructPath(start, deliveryLocation, astar.cameFrom); truckPaths.Add(path); pathLength = path.Count * BaseConstants.PolygonSize; deliveryTime = pathLength / BaseConstants.TruckSpeed + BaseConstants.DropDeliveryTime; truck.currentPosition = deliveryLocation; truck.time += deliveryTime; truck.status = Status.OnMission; truck.log.Add(new Log(truck.id, truck.currentPosition, orders.Where(x => (x.x == truck.currentPosition.x && x.y == truck.currentPosition.y)).First().address, truck.time, truck.status, "Delivery finished")); } //astar = new AStarSearch(groundGrid, new Location(truckOrders.Last().x, truckOrders.Last().y, 0), Depot); //path = astar.ReconstructPath(new Location(truckOrders.Last().x, truckOrders.Last().y, 0), Depot, astar.cameFrom); //truckPaths.Add(path); return(Truck.truckStatusUpdate(truckPaths, TruckTime)); }